Skip to main content

DxChartLegend Class

Defines a chart legend.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v25.1.dll

NuGet Package: DevExpress.Blazor

Declaration

public class DxChartLegend :
    DxComplexSettingsComponent<DxChartLegend, ChartLegendModel>,
    IModelProvider<ChartTitleModel>

Remarks

Use DxChartLegend objects to customize legend settings for the following components:

DxChart<T>
A control that visualizes bound data as graphs: bar, area, line, and others.
DxPieChart<T>
A control that visualizes data as Pie and Donut charts.
DxPolarChart<T>
A control that visualizes bound data as graphs in polar coordinates.

A chart component can display a legend - an explanatory component that helps you identify a series. The legend lists all series (for <DxChart> and <DxPolarChart>) or data points (for <DxPieChart>) as legend items. Each item consists of a marker and text that identify the associated series or data point.

Charts - Legend Customization

<DxChart Data="@DataSource">
    <DxChartBarSeries ArgumentField="@((StatisticPoint v) => v.Country)"
                      ValueField="@((StatisticPoint v) => v.Population24)"
                      Name="2024" />
    <DxChartLineSeries ArgumentField="@((StatisticPoint v) => v.Country)"
                       ValueField="@((StatisticPoint v) => v.Population23)"
                       Name="2023" />
    <DxChartLegend Orientation="Orientation.Vertical"
                   HorizontalAlignment="HorizontalAlignment.Right"
                   Position="RelativePosition.Outside"
                   AllowToggleSeries="true" />
</DxChart>

Run Demo: Charts - Legend Customization

Refer to the following article for more information about legend configuration in Blazor Charts: Descriptive Elements - Legend.

Respond to Legend Item Clicks

When users click legend items, Chart components raise their LegendClick events (DxChart.LegendClick, DxPolarChart.LegendClick, or DxPieChart.LegendClick). In a handler, you can use the event’s argument properties to obtain information about the series (for all chart types) and the point (for DxPieChart only) associated with the clicked legend item.

<DxChart Data="@DataSource"
         @ref="chart"
         Width="1200px"
         Height="300px"
         SeriesSelectionMode="ChartSelectionMode.Single"
         LegendClick="@OnChartLegendClick">
    <DxChartBarSeries ArgumentField="@((StatisticPoint v) => v.Country)"
                      ValueField="@((StatisticPoint v) => v.Population24)"
                      Name="2024"
                      HoverMode="ChartSeriesPointHoverMode.None" />
    <DxChartLineSeries ArgumentField="@((StatisticPoint v) => v.Country)"
                       ValueField="@((StatisticPoint v) => v.Population23)"
                       Name="2023"
                       HoverMode="ChartContinuousSeriesHoverMode.None" />
    <DxChartLegend HoverMode="ChartLegendHoverMode.None" />
</DxChart>

@code {
    DxChart<StatisticPoint> chart;

    public void OnChartLegendClick(ChartLegendClickEventArgs args) {
        if (args.Series != null) {
            var SeriesName = args.Series.Name;
            var TotalPopulation = SeriesName == "2023" ? DataSource.Select(x => x.Population23).Sum() : DataSource.Select(x => x.Population24).Sum();
            ShowDetailDialog(SeriesName, TotalPopulation);
        }
    }
    // ...
}

Inheritance

Object
ComponentBase
DxSettingsComponent<DevExpress.Blazor.Internal.ChartLegendModel>
DxComplexSettingsComponent<DxChartLegend, DevExpress.Blazor.Internal.ChartLegendModel>
DxChartLegend
See Also