Vizor.ECharts 0.8.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package Vizor.ECharts --version 0.8.6                
NuGet\Install-Package Vizor.ECharts -Version 0.8.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Vizor.ECharts" Version="0.8.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Vizor.ECharts --version 0.8.6                
#r "nuget: Vizor.ECharts, 0.8.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Vizor.ECharts as a Cake Addin
#addin nuget:?package=Vizor.ECharts&version=0.8.6

// Install Vizor.ECharts as a Cake Tool
#tool nuget:?package=Vizor.ECharts&version=0.8.6                

Vizor.ECharts

Blazor wrapper for Apache ECharts.

  • Supports .NET >= 6.0
  • Ships with echarts 5.4.3
  • Apache-2.0 Licensed (same as echarts)
  • Lots of examples in the Vizor.ECharts.Demo project
  • Refer to the official echarts cheat sheet for a quick introduction

The project currently is not yet production ready, it will be around September/October. Small API changes will occur frequently until version >= 1.0.0 .

How to include

  1. Add a package reference to Vizor.ECharts
  2. Add the following script to your _Host.cshtml or _Layout.cshtml file
<script src="_content/Vizor.ECharts/js/vizor-echarts-min.js"></script>

See the example from the demo application.

How to use

The bindings are nearly identical to the javascript/typescript version. This makes it very easy to translate the examples from the official documentation to C#.

For example: a simple pie chart.

Add a using statement:

@using Vizor.ECharts;

Chart component in your .razor file:

<Vizor.ECharts.EChart Options="@options" Width="auto" Height="400px" />

Chart options in the code section of your razor file:

private ChartOptions options = new()
{
	Title = new()
	{
		Text = "Referer of a Website",
		Subtext = "Fake Data",
		Left = "center"
	},
	Tooltip = new()
	{
		Trigger = ECharts.TooltipTrigger.Item
	},
	Legend = new()
	{
		Orient = Orient.Vertical,
		Left = "left"
	},
	Series = new()
	{
		new PieSeries()
		{
			Name = "Access From",
			Radius = new CircleRadius("50%"),
			Data = new List<PieSeriesData>()
			{
				new() { Value = 1048, Name = "Search Engine" },
				new() { Value = 735, Name = "Direct" },
				new() { Value = 580, Name = "Email" },
				new() { Value = 484, Name = "Union Ads" },
				new() { Value = 300, Name = "Video Ads" },
			},
			Emphasis = new()
			{
				ItemStyle = new()
				{
					ShadowBlur = 10,
					ShadowOffsetX = 0,
					ShadowColor = Color.FromRGBA(0, 0, 0, 0.5)
				}
			}
		}
	}
};

See the full C# code.

Data loading

Most examples that you will find online have very basic datasets. However, in real life, data sets are often huge and come from various different sources.

Vizor.ECharts allows you to define data in 3 different ways:

  1. Inside the ChartOptions, as demonstrated in most samples
  2. Using async data sources in C#, allowing you to fetch data directly from the database
  3. Using remote data sources (e.g.: REST API) fetched by the browser

Async data loading

Specify the DataLoader parameter, this can be a sync or async function.

<Vizor.ECharts.EChart Options="@options" DataLoader="@LoadChartData" Width="800px" Height="400px" />

Typically in the data loader function you update the Series property. However, you can update any chart option.

private async Task LoadChartData()
{
	options.Series = ... ;
}

See full example.

Remote data loading

Any Data property of type object? accepts a ExternalDataSource allowing you to specify the external data source.

Data = new ExternalDataSource("https://example.com/api/data/sunburst_simple.json")

See full example.

It is also possible to provide a simple path expression to retrieve only a part of the external data:

Data = new ExternalDataSource("https://example.com/api/data/sankey_simple.json") { Path = "nodes" }

Additional credentials, headers, policies, ... can also be supplied. See ExternalDataSource and FetchOptions for more details.

Datasets

ECharts allows datasets to be transformed. This allows for simplified data retrieval, without the need to have a separate dataset for different charts or chart types.

See Dataset example .

See also the echarts dataset documentation and tutorial .

Javascript functions

ECharts sometimes allows you to assign custom functions instead of values. This can be achieved with the JavascriptFunction class. The class accepts a raw Javascript function that is evaluated in the browser.

For example:

Formatter = new JavascriptFunction("function (param) { return param.name + ' (' + param.percent * 2 + '%)'; }")

See full example.

Updating charts

Chart options and/or data can be updated. For example: to show a never ending line chart, a temperature gauge, ... .

First store a reference to your chart.

<Vizor.ECharts.EChart @ref="chart" Options="@options" Width="800px" Height="400px" />
...
private Vizor.ECharts.EChart? chart;

Next modify the chart options. Modified options have full support for Javascript functions and external data sources.

private async Task UpdateChartAsync()
{
	if (chart == null)
		return;

	// modify chart options
	
	await chart.UpdateAsync();
}

See full example.

Filing Bugs / Future Development

See Issues for a list of open tasks/bugs.

Please provide a runnable sample using the ECharts Online Editor and a description of what is wrong with the C# mapping.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

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
0.9.0 2,758 3/12/2024
0.8.9 472 8/9/2023
0.8.8 171 8/5/2023
0.8.7 170 8/3/2023
0.8.6 173 8/2/2023
0.8.5 183 8/1/2023
0.8.4 165 8/1/2023
0.8.3 169 8/1/2023
0.8.2 164 7/31/2023
0.8.1 152 7/31/2023
0.8.0 167 7/31/2023