TraceLd.PlotlySharp 1.0.1

Unofficial C# wrapper for Plotly's Streaming and REST APIs

Install-Package TraceLd.PlotlySharp -Version 1.0.1
dotnet add package TraceLd.PlotlySharp --version 1.0.1
<PackageReference Include="TraceLd.PlotlySharp" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TraceLd.PlotlySharp --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

PlotlySharp

License
nuget
Framework
Build Status

Unofficial C# wrapper for Plotly's REST APIs

example
example
example
example

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);
}

PlotlySharp

License
nuget
Framework
Build Status

Unofficial C# wrapper for Plotly's REST APIs

example
example
example
example

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);
}

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.1 228 8/23/2019
1.0.0 124 8/23/2019
1.0.0-alpha 98 8/20/2019