XPlot离线使用

XPlot offline usage

现在,如果我使用此代码:

var chart = Chart.Plot(new[]
{
    new Graph.Scatter()
    {
          x = data.Select(o => o.X),
          y = data.Select(o => o.Y),
          name = "Loss",
          mode = "lines"
     }
});

chart.WithXTitle("Xs");
chart.WithYTitle("Ys");
chart.WithTitle("Chart title");

File.WriteAllText("C:\Users\picolino\Documents\chart.html", chart.GetHtml());

它生成了一个 html 文件,通过网络直接引用 ploty-latest.min.js

<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>

那么我可以使用 XPlot 库导出交互式 (html+js) 或至少是静态(图像)图表以供离线使用吗?

这里的库的 github 页面上已经有一个功能请求:https://github.com/fslaborg/XPlot/issues/43

如果您想将其另存为图像或 pdf,可以使用将 html 转换为这些文件格式的库。然而,这将删除情节的动态特征。

另一种解决方案是在您的本地计算机上获取 javascript:

您可以将 plotly-latest.min.js 文件下载到本地输出文件夹并替换为:
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
有了这个:
<script src="/plotly-latest.min.js"></script>

您可以通过在 C# 中打开文件并以编程方式执行字符串替换来替换它。 然而,这意味着您不会获得这些图表的最新版本和错误修复