Component for convenient rendering of Apache ECharts.
HxEChart
component and related types are distributed in a separate NuGet package: Havit.Blazor.Components.Web.ECharts.
The HxEChart
component is not intended to fully replicate the entire ECharts API. Instead, it provides a simple, user-friendly wrapper around the library.
Use .NET anonymous objects to pass options to the chart.
For a complete list of available options and their descriptions, refer to the ECharts documentation.
<HxEChart Options="_options" AutoResize="true" />
@code {
private object _options;
protected override void OnParametersSet()
{
// use anonymous object to pass options to the chart
_options = new
{
Tooltip = new
{
Trigger = "item"
},
Legend = new
{
Top = "5%",
Left = "center",
TextStyle = new { Color = "#888" }
},
Series = new object[]
{
new
{
Name = "Access From",
Type = "pie",
Radius = new string[] { "40%", "70%" },
AvoidLabelOverlap = false,
ItemStyle = new
{
BorderRadius = 10,
BorderColor = "#fff",
BorderWidth = 2
},
Label = new
{
Show = false,
Position = "center",
},
Emphasis = new
{
Label = new
{
Show = true,
FontSize = 40,
FontWeight = "bold"
}
},
LabelLine = new
{
Show = false
},
Data = new object[]
{
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" }
}
}
}
};
}
}
The HxEChart
component is not bound to any specific version or source of the library. For convenience, you can use our helper method to
generate the <script>
tag that references a supported version from the CDN.
Add the following line at the end of your App.razor
file, just before the closing </body>
tag:
@((MarkupString)HxEChartsSetup.RenderEChartsJavaScriptReference())
To handle clicks on the chart, use the OnClick
event. The event handler receives an EChartClickEventArgs object as a parameter.
The EChartClickEventArgs
class contains properties such as SeriesIndex
, DataIndex
, Name
, and Value
.
Click to blank area of the chart will return null
values for these properties.
Use HxECharts.JSFunc
class to pass a raw JavaScript function as a parameter:
You can find more examples of how to use the HxEChart
component, including some higher-level, pre-built
components for individual chart types, in our Blocks section.
Name | Type | Description |
---|---|---|
OptionsREQUIRED | object |
Options for the chart. See ECharts Option for more details. |
AutoResize | bool |
Indicates whether the chart should automatically resize. Default is false . |
ChartId | string |
Unique identifier for the HTML element representing the chart. |
Height | string |
The height of the chart. Default is 400px . |
Name | Type | Description |
---|---|---|
OnClick | EventCallback<EchartClickEventArgs> |
Invoked when the chart is clicked. |