Skip to content

curiosity-ai/plotly-sharp

Repository files navigation

Build Status

Plotly.Sharp provides a strongly-typed binding to generate embedded HTML using Plotly.

Nuget

Plotly.Bridge provides a strongly-typed binding to use Plotly on Bridge.Net applications.

Nuget

Both libraries are automatically generated from the official plotly.js API schema, and includes the respective plotly.min.js file as part of the Nuget package.

Example:

var data = new[]{
                    new []{ 1f, 20f, 30f },
                    new []{20f,  1f, 60f },
                    new []{30f, 60f,  1f }
                };

//Or use the shortcut:
// var data = data.m( 1f, 20f, 30f)
//                .r(20f,  1f, 60f)
//                .r(30f, 60f,  1f);

var chart = new Plot(
                Plot.traces(
                     Traces.heatmap(
                            Heatmap.z(data))));

//For Plotly.Bridge, you can directly render the chart to an HTMLElement:
    document.body.appendChild(chart.Render());

//For Plotly.Sharp, you can create the embedded HTML string as follows:
    var html = chart.Render().ToHTML();

You can follow the official documentation from Plotly, as the types and usage are almost exactly the same (one minor but important change: some of the objects on C# have the first letter in upper-case (like Traces.heatmap on the example above).

Note: Event types have been manually created, and have not been all validated against plotly's events. If you find any definition that doesn't match the expected one from plotly, please open an issue for it!

This project is derived from the awesome work by Cody Johnson on the F# bindings.