Home

Dump Plotly.Net

Hello,

I'm using Plotly.Net for charts. It allows interactions like zooming and supports tooltips. Wouldn't it be great to support Dumping the output in LinqPad?

I think it will take some adjustments to the plotting engine to support this, which I would like to contribute. However, I'm stuck with the correct way to Dump the charts in LinqPad. Maybe someone can help me there.

At the moment, Plotly.Net generates complete HTML documents. This does not work with LinqPad (I think), and must be broken down.

I managed to Dump a chart from it's individual parts. This takes 4 steps:

  • Add Plotly.js from an URL
  • Add the custom JS script for the plot
  • Add a Div element for the script to plot into
  • Invoke the script
Util.HtmlHead.AddScriptFromUri("https://cdn.plot.ly/plotly-2.21.0.min.js");
Util.HtmlHead.AddScript(script);
Util.RawHtml(html).Dump("Chart");
Util.InvokeScript(false, "renderPlotly_f5d66a84bf964fd1afcf5cf86cf68509");

This works fine from within a LinqPad script, where Util can be accessed.

My question is, how would one implement this in the Plotly.Net library without any reference to LinqPad?

I found in the documentation, that I can Dump the RawHtml as

return new XElement("LINQPad.HTML",
      new XElement("div", new XAttribute("id", "f5d66a84-bf96-4fd1-afcf-5cf86cf68509"))
  );

I guess I could use Reflection to invoke the other methods. Does anyone have a better idea?

Thanks for any hints or suggestions
Peter

Comments

Sign In or Register to comment.