TraceLd.PlotlySharp
1.0.1
dotnet add package TraceLd.PlotlySharp --version 1.0.1
NuGet\Install-Package TraceLd.PlotlySharp -Version 1.0.1
<PackageReference Include="TraceLd.PlotlySharp" Version="1.0.1" />
paket add TraceLd.PlotlySharp --version 1.0.1
#r "nuget: TraceLd.PlotlySharp, 1.0.1"
// Install TraceLd.PlotlySharp as a Cake Addin #addin nuget:?package=TraceLd.PlotlySharp&version=1.0.1 // Install TraceLd.PlotlySharp as a Cake Tool #tool nuget:?package=TraceLd.PlotlySharp&version=1.0.1
PlotlySharp
Unofficial C# wrapper for Plotly's REST APIs
Installation
Package Manager
PM> Install-Package TraceLd.PlotlySharp
.NET CLI
dotnet add package TraceLd.PlotlySharp
Paket CLI
paket add TraceLd.PlotlySharp
or simply add the package via your IDE's NuGet package manager.
Usage
Create a chart using the built-in PlotlyChart type
This method currently supports only the following chart types:
- Bar
- Contour
- Heatmap
- Pie
- Scatter
If the chart you're using is not on that list, you can either create it using a JSON Object string (this will be explained later in this document) or you can try using the generic Trace
type.
To see all possible properties and what they are responsible for click here. The C# types are a direct map from plotly's JSON objects.
using TraceLd.PlotlySharp;
using TraceLd.PlotlySharp.Api;
using TraceLd.PlotlySharp.Api.Traces;
// very basic example, hardcoding credentials is HIGHLY not recommended
PlotlyCredentials Func() => new PlotlyCredentials {Username = "username", Token = "token"};
// create a plotly client that will communicate with Plotly API
// provide your own HttpClient
PlotlyClient plotlyClient = new PlotlyClient(Client, Func);
// create a chart
PlotlyChart myChart = new PlotlyChart
{
Figure = new Figure
{
Data = new ArrayList { new BarTrace
{
X = new ArrayList {1, 2, 3},
Y = new ArrayList {1, 2, 3},
}, new BarTrace
{
X = new ArrayList {1, 2, 3},
Y = new ArrayList {1, 2, 3},
}},
},
Height = 1000,
Width = 1000
};
// send the chart to Plotly to compute an image and receive it as a PNG file as byte array
byte[] myImg = await plotlyClient.GetChartAsByteArray(myChart);
// save it to a file
var imgStream = new MemoryStream(myImg);
using (var fileStream = File.Create("example1.png"))
{
imgStream.CopyTo(fileStream);
}
You can see this example in more detail here.
Create a chart using a JSON object string
This method supports everything that the plot.ly API supports (supports all chart types that Plotly provides). For all possible chart options click here.
using TraceLd.PlotlySharp;
// very basic example, hardcoding credentials is HIGHLY not recommended
PlotlyCredentials Func() => new PlotlyCredentials {Username = "username", Token = "token"};
// create a plotly client that will communicate with Plotly API
// provide your own HttpClient
PlotlyClient plotlyClient = new PlotlyClient(Client, Func);
// create a chart using a JSON object string (must be escaped)
var escapedJsonObjectString = "{\"figure\": {\"data\": [{\"y\": [10, 10, 2, 20]}], \"layout\": {\"width\": 700}}, \"width\": 1000, \"height\": 500, \"format\": \"png\", \"encoded\": false}";
byte[] myImg2 = await plotlyClient.GetChartAsByteArray(escapedJsonObjectString);
// save it to a file
var imgStream2 = new MemoryStream(myImg2);
using (var fileStream = File.Create("example2.png"))
{
imgStream2.CopyTo(fileStream);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 12.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.1 | 716 | 8/23/2019 |
1.0.0 | 505 | 8/23/2019 |
1.0.0-alpha | 303 | 8/20/2019 |