简体   繁体   English

F# Plotly.NET 图表描述问题

[英]Issue with F# Plotly.NET chart descriptions

I'm trying to plot a line chart with a description, using the first method identified in https://plotly.net/00_2_display-options.html .我正在尝试 plot 带有描述的折线图,使用https://plotly.net/00_2_display-options.html中确定的第一种方法。

While the code runs, and the chart is correctly plotted, I can't see the description.当代码运行并且图表绘制正确时,我看不到描述。

Here's the code block:这是代码块:

let description1 =
    ChartDescription.create "Cumulative Growth of Market and HmL Factors" ""

Chart.combine(
    [Chart.Line(
        hmlGrowth,
        Name="Hml")
     Chart.Line(
         marketGrowth,
         Name="Mkt")
    |> Chart.withDescription(description1)
    |> Chart.withYAxisStyle (AxisType = StyleParam.AxisType.Log)
    |> Chart.withXAxisStyle("Date")
    ]
)

If I add |> Chart.show I get a compilation error, perhaps because I'm using a Notebook.如果我添加 |> Chart.show 我会得到一个编译错误,可能是因为我使用的是笔记本。

Any help is greatly appreciated.任何帮助是极大的赞赏。



EDIT: managed to get in touch with the authors, should be sorted.编辑:设法与作者取得联系,应该进行排序。 https://github.com/plotly/Plotly.NET/issues/281 https://github.com/plotly/Plotly.NET/issues/281

This works if you run code in F# Interactive and display it using Chart.show , but it does not work in .NET Interactive.如果您在 F# Interactive 中运行代码并使用Chart.show显示它,这会起作用,但它在 .NET Interactive 中不起作用。 When using Chart.show , the description is added below the chart as ordinary HTML block, so I suspect the formatter for .NET Interactive just somhow ignores this part.使用Chart.show时,描述作为普通 HTML 块添加到图表下方,因此我怀疑 .NET Interactive 的格式化程序只是不知何故忽略了这部分。 I think this is a bug and it would be good to report & fix this.我认为这是一个错误,最好报告并修复它。

As a workaround, it seems that you can post-process the HTML generated for charts and add whatever additional code you need by getting the HTML and then returning it using the HTML helper.作为解决方法,您似乎可以对为图表生成的 HTML 进行后处理,并通过获取 HTML 添加所需的任何其他代码,然后使用HTML帮助器返回它。 For example:例如:

let showWithHeading s c = 
    HTML("<h3>" + s + "</h3>" + Plotly.NET.GenericChart.toChartHTML(c))

Chart.combine(
    [Chart.Line(
        hmlGrowth,
        Name="Hml")
     Chart.Line(
         marketGrowth,
         Name="Mkt")
    |> Chart.withYAxisStyle (AxisType = StyleParam.AxisType.Log)
    |> Chart.withXAxisStyle("Date")
    ]
)
|> showWithHeading "Cumulative Growth of Market and HmL Factors"

I second Tomas's point that it looks like a bug with Plotly.NET's current notebook formatter.我支持 Tomas 的观点,它看起来像是 Plotly.NET 当前笔记本格式化程序的错误。

One option is to use Chart.withTitle一种选择是使用Chart.withTitle

#r "nuget:Plotly.NET, 2.0.0-preview.18"
#r "nuget:Plotly.NET.Interactive, 2.0.0-preview.18"

open System
open Plotly.NET

let hmlGrowth = [
    DateTime(2005, 1,1), 1.0
    DateTime(2006,1,1), 2.0 ]

let marketGrowth = hmlGrowth |> List.map (fun (a,b) -> a, b + 1.0)

Chart.combine([
    Chart.Line(
        hmlGrowth,
        Name="Hml")
    Chart.Line(
        marketGrowth,
        Name="Mkt")
    ])
|> Chart.withYAxisStyle (AxisType = StyleParam.AxisType.Log)
|> Chart.withXAxisStyle ("Date")
|> Chart.withTitle("Cumulative Growth of Market and HmL Factors")

在此处输入图像描述

Managed to get in touch with the authors, should be sorted: https://github.com/plotly/Plotly.NET/issues/281好不容易联系上了作者,应该整理一下: https://github.com/plotly/Plotly.NET/issues/281

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM