XPlot中的选项和WithSize等仅适用于某些图表吗?

时间:2016-10-12 04:31:14

标签: f# fslab

我在FSLab教程中尝试了Chart.WithSizedisplayZoomButtons = true,但似乎没有任何改变输出。

直接使用XPlot.GoogleCharts的其他项目也是如此。

enter image description here

我错过了什么吗?

2 个答案:

答案 0 :(得分:1)

从nuget下载Plotly 1.4.2并替换XPlot的FSLab包目录中的dll(参见Plotting with Xplotly Q)。然后你可以使用Xplotly的控件放​​大和缩小,保存图表等。例如:

#load @"..\..\FSLAB\packages\FsLab\FsLab.fsx"
open XPlot.Plotly
open XPlot.Plotly.Graph
open XPlot.Plotly.Html
//open XPlot.GoogleCharts

let layout = Layout(title = "Basic Bar Chart")
["giraffes", 20; "orangutans", 14; "monkeys", 23]
    |> Chart.Bar
    |> Chart.WithLayout layout
    |> Chart.WithHeight 400
    |> Chart.WithWidth 700
    |> Chart.Show

enter image description here

答案 1 :(得分:0)

使用Plotly非常准确的图表解决方案(并且它可以工作):

open Newtonsoft.Json

let html = """<head>
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
  <div id="myDiv" style="width: 100%; height: 100%;"></div>
  <script>
    var data = __DATA__;
    var layout = __LAYOUT__;
    Plotly.newPlot('myDiv', data, layout);
  </script>
</body>"""

let (=>) k v = k, (v:>obj)

let doPlot data layout =
    let data = JsonConvert.SerializeObject data
    let layout = JsonConvert.SerializeObject layout
    let path = Path.GetTempPath() + DateTime.Now.Ticks.ToString() + ".html"
    File.WriteAllText(path, html.Replace("__DATA__", data).Replace("__LAYOUT__", layout))
    System.Diagnostics.Process.Start(path)

let layout =
    [ "title" => "Plot"
      "xaxis" => dict [
        "title" => "Ticks"
        "showgrid" => false
        "zeroline" => false
      ]
      "yaxis" => dict [
        "title" => "Price"
        "showline" => false
      ]
    ] |> dict

let data = [
    dict [ "x" => [1999; 2000; 2001; 2002]
           "y" => [16; 5; 11; 9]
         ]
    ]

doPlot data layout