|
| 1 | +--- |
| 2 | +title: Legend |
| 3 | +page_title: Chart Legend |
| 4 | +description: Discover the capabilities of the Chart Legend in Telerik UI for Blazor. Learn how to show it, and explore the customization options. |
| 5 | +slug: chart-legend |
| 6 | +tags: telerik,blazor,chart,legend,customizations |
| 7 | +published: True |
| 8 | +position: 100 |
| 9 | +--- |
| 10 | + |
| 11 | +# Telerik Chart Legend |
| 12 | + |
| 13 | +The Telerik Chart for Blazor can show a visual guide with details about the series or elements in the Chart. This article explores how to add a Chart legend, identify its building blocks, and customize the legend appearance. |
| 14 | + |
| 15 | +## Adding a Legend |
| 16 | + |
| 17 | +1. Add the `<ChartLegend>` child tag and set the `Visible` parameter to `true` |
| 18 | +1. Add the `Name` parameter to all Chart series that must be visible in the legend. |
| 19 | + |
| 20 | +## Chart Legend Customization |
| 21 | + |
| 22 | +You can customize the Chart legend by adding nested (child) tags to the `<ChartLegend>` and use their parameters for fine tuning. |
| 23 | + |
| 24 | +The structure of the nested tags is `<ChartLegend*Specifics*>`, where the specifics can be: |
| 25 | + |
| 26 | +* `Title` |
| 27 | +* `Item` |
| 28 | +* `Border` |
| 29 | + |
| 30 | +>note Use the IntelliSense to explore the nested tags. |
| 31 | +
|
| 32 | +## Legend Settings in the Chart Series |
| 33 | + |
| 34 | +You can customize individual items in the legend for a specific Chart series by adding the `<ChartSeriesLegendItem>` (child tag of `<ChartSeries>`) and its nested tag settings and parameters. |
| 35 | + |
| 36 | +The structure of the nested tags is `<ChartSeriesLegend*Specifics*>`, where the specifics can be: |
| 37 | + |
| 38 | +* `Markers` |
| 39 | +* `Highlight` |
| 40 | +* and others |
| 41 | + |
| 42 | +>note Use the IntelliSense to explore the nested tags. |
| 43 | +
|
| 44 | +## Example |
| 45 | + |
| 46 | +Customize the legend items by using nested tag settings. |
| 47 | + |
| 48 | +````CSHTML |
| 49 | +<TelerikChart> |
| 50 | + <ChartSeriesItems> |
| 51 | + <ChartSeries Type="ChartSeriesType.Column" Name="Product 1" Data="@series1Data"> |
| 52 | + <ChartSeriesLegendItem> |
| 53 | + <ChartSeriesLegendItemMarkers Background="blue"> |
| 54 | + </ChartSeriesLegendItemMarkers> |
| 55 | + </ChartSeriesLegendItem> |
| 56 | + </ChartSeries> |
| 57 | + <ChartSeries Type="ChartSeriesType.Column" Name="Product 2" Data="@series2Data"> |
| 58 | + <ChartSeriesLegendItem Type="@ChartLegendItemType.Area"> |
| 59 | + <ChartSeriesLegendItemMarkers Background="#00ff00"> |
| 60 | + </ChartSeriesLegendItemMarkers> |
| 61 | + </ChartSeriesLegendItem> |
| 62 | + </ChartSeries> |
| 63 | + </ChartSeriesItems> |
| 64 | +
|
| 65 | + <ChartCategoryAxes> |
| 66 | + <ChartCategoryAxis Categories="@xAxisItems"></ChartCategoryAxis> |
| 67 | + </ChartCategoryAxes> |
| 68 | +
|
| 69 | + <ChartTitle Text="Quarterly revenue"></ChartTitle> |
| 70 | +
|
| 71 | + <ChartLegend Position="ChartLegendPosition.Right" Visible="true"> |
| 72 | + <ChartLegendTitle Text="Revenue per product" |
| 73 | + Background="lightblue" |
| 74 | + Color="black"> |
| 75 | + </ChartLegendTitle> |
| 76 | + <ChartLegendItem> |
| 77 | + <ChartLegendItemMarkers Type="@ChartSeriesMarkersType.Cross" |
| 78 | + Background="#00ff00"> |
| 79 | + </ChartLegendItemMarkers> |
| 80 | + </ChartLegendItem> |
| 81 | + </ChartLegend> |
| 82 | +</TelerikChart> |
| 83 | +
|
| 84 | +@code { |
| 85 | + public List<object> series1Data = new List<object>() { 10, 2, 5, 6 }; |
| 86 | + public List<object> series2Data = new List<object>() { 5, 8, 2, 7 }; |
| 87 | + public string[] xAxisItems = new string[] { "Q1", "Q2", "Q3", "Q4" }; |
| 88 | +} |
| 89 | +```` |
| 90 | + |
| 91 | +## See Also |
| 92 | + |
| 93 | +[Live Chart Legend Customization Demo](https://demos.telerik.com/blazor-ui/chart/legend-customization) |
0 commit comments