Plotly.NET
https://plotly.com/csharp/creating-and-updating-figures/
Pros:
- Uses
Plotly.JS
Cons:
- Documentation is mostly in F#.
- Poor IntelliSense.
Getting Started
dotnet add package plotly.net
using Plotly.NET;
using Microsoft.FSharp.Core; // less verbose and more helpful intellisense(?)
Basics
General design philosophy:
- Initialize a generic chart
- Style the chart
- Display or save the chart
Initialize a Chart
A chart consists of:
- data: a collection of traces, which represent the data and chart type.
- layout: controls the axis positions and styles.
- config: high-level properties like making all chart elements editable.
double[] x = new double[] { 1, 2 };
double[] y = new double[] { 5, 10 };
GenericChart.GenericChart chart = Chart2D.Chart.Point<double, double, string>(x: x, y: y);
// or
GenericChart.GenericChart chart = Chart.Line(…)
Styling a Chart
chart
.WithTraceName("*Chart name*", true)
.WithXAxisStyle("title: Title.init("*xAxis*"), ShowGrid: false, ShowLine: true)
.WithYAxisStyle("title: Title.init("*yAxis*"), ShowGrid: false, ShowLine: true)
.Show();
Displaying a Chart
chart.Show();
Image Export
dotnet add package plotly.net.imageexport
using Plotly.Net.ImageExport;
using Plotly.Net.GenericChartExtensions;
chart.SaveJPG // | SavePNG | SaveSVG (*"path*", width=*n*, height=*m*);
Marker Symbols
Marker symbols used in charts:
StyleParam.MarkerSymbol.Square