Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

ant-design-charts-blazor

> 编程语言
Open source

A Blazor chart library, based on G2Plot

185 stars0 likes1 views
WebsiteGitHub

About

A Blazor chart library, based on G2Plot

ant-design-charts-blazor

A Blazor chart library, based on G2Plot

English | 简体中文

Current Version

  • Release:
  • Development:

Installation Guide

  • Go to the project folder of the application and install the Nuget package reference

    bash
    $ dotnet add package AntDesign.Charts
    • Add namespace in _Imports.razor
    csharp
    @using AntDesign.Charts
  • Finally, it can be referenced in the `.razor' component!

…

Using JavaScript Functions in Configuration

When configuring charts, you can define JavaScript functions for properties like formatter or properties ending with Func. These functions will be properly converted from string representations to actual JavaScript functions.

Supported Function Syntax

The following JavaScript function syntaxes are supported:

  1. Standard function declarations:

    csharp
    config.Tooltip.Formatter = "function(datum) { return { name: datum.year, value: '$' + datum.value.toFixed(2) }; }";
  2. Arrow functions:

    csharp
    config.Tooltip.Formatter = "(datum) => { return { name: datum.year, value: '$' + datum.value.toFixed(2) }; }";
  3. Concise arrow functions (implicit return):

    csharp
    config.Tooltip.Formatter = "datum => '$' + datum.value.toFixed(2)";
  4. Simple expressions:

    csharp
    config.Meta.Value.Formatter = "'$' + datum * 100";

Using Functions with Array Properties

JavaScript functions can also be defined within objects inside arrays:

csharp
config.Annotations = new[]
{
    new
    {
        type = "text",
        position = new[] { "min", "median" },
        content = "Middle point",
        formatter = "function(item) { return item.value.toFixed(2); }"
    }
};

Event Handling

Charts support various events that you can handle in your Blazor code. You can use the On and Once methods to subscribe to chart events.

Basic Event Usage

…

Available Events

Common chart events include:

  • plot:click - Triggered when clicking on the chart
  • plot:dblclick - Triggered when double-clicking on the chart
  • plot:mousemove - Triggered when moving the mouse over the chart
  • plot:mouseenter - Triggered when the mouse enters the chart area
  • plot:mouseleave - Triggered when the mouse leaves the chart area
  • element:click - Triggered when clicking on a chart element (e.g., line, bar)
  • legend-item:click - Triggered when clicking on a legend item

One-time Event Handling

Use Once to subscribe to an event that should only be handled once:

csharp
await chartRef.Once("plot:click", (data) =>
{
    // This handler will only be called once
    Console.WriteLine($"First click at x: {data.X}, y: {data.Y}");
});

Event Data

The event data is passed as System.Text.Json.JsonElement by default, which you can handle directly or deserialize into a specific type using the generic methods. The actual structure of the event data depends on the event type and chart type.

A typical event data structure looks like this:

…

Example of handling event data:

csharp
chartRef.On("element:click", (data) =>
{
    Console.WriteLine($"Clicked element: Type={data.Data.Type}, Sales={data.Data.Sales}");
    Console.WriteLine($"Position: X={data.X}, Y={data.Y}");
    Console.WriteLine($"Style: Color={data.Color}, Shape={data.Shape}");
});

Unsubscribing from Events

You can unsubscribe from events using the Off method. There are two ways to use it:

  1. Unsubscribe from a specific event handler:
csharp
@code {
    IChartComponent chartRef;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            // Subscribe to the event with a method
            chartRef.On("plot:click", HandleChartClick);

            // Later, unsubscribe this specific handler
            chartRef.Off("plot:click", HandleChartClick);
        }
    }

    private void HandleChartClick(JsonElement data)
    {
        Console.WriteLine($"Clicked: {data}");
    }
}
  1. Unsubscribe from all handlers of a specific event or all events:
csharp
// Unsubscribe from all handlers of a specific event
await chartRef.Off("plot:click");

// Unsubscribe from all event handlers
await chartRef.Off();

It's good practice to unsubscribe from events when they are no longer needed or when the component is being disposed:

…

Links

  • Official Blazor Documentation

Contributing

If you would like to contribute, feel free to create a Pull Request, or give us Bug Report.

Donation

This project is an MIT-licensed open source project. In order to achieve better and sustainable development of the project, we expect to gain more backers. We will use the proceeds for community operations and promotion. You can support us in any of the following ways:

  • OpenCollective
  • Wechat
  • Alipay

We will put the detailed donation records on the backer list.

❓ Community Support

If you encounter any problems in the process, feel free to ask for help via following channels. We also encourage experienced users to help newcomers.

  • (Chinese & English)

  • (Chinese)

    Scan QR Code with DingTalk

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#blazorblazor-componentscharts

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言