Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions components/chart/legend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
title: Legend
page_title: Chart Legend
description: Discover the capabilities of the Chart Legend in Telerik UI for Blazor. Learn how to show it, and explore the customization options.
slug: chart-legend
tags: telerik,blazor,chart,legend,customizations
published: True
position: 100
---

# Telerik Chart Legend
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop Telerik from the heading.


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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chart legend and Chart Legend are used somewhat inconsistently. I would go with Chart Legend or Legend when referring to the feature or the component.


## Adding a Legend

1. Add the `<ChartLegend>` child tag and set the `Visible` parameter to `true`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always end your sentences with the proper punctuation. In this case, you need a period at the end.

1. Add the `Name` parameter to all Chart series that must be visible in the legend.

## Chart Legend Customization
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retain your heading style. For consistency, go with the -ing form throughout.

## Customizing the Chart Legend

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, would Styling be a better term here?


You can customize the Chart legend by adding nested (child) tags to the `<ChartLegend>` and use their parameters for fine tuning.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider a simple re-write placing the goal as context and focusing on what needs to be done next:

To fine tune the Chart Legend, add nested (child) tags to the <ChartLegend> and use their parameters.


The structure of the nested tags is `<ChartLegend*Specifics*>`, where the specifics can be:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is a bit ambiguous. Is this an exhaustive list of possible child tags? Or are these just a few examples of what can be done?


* `Title`
* `Item`
* `Border`

>note Use the IntelliSense to explore the nested tags.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>note Use IntelliSense to explore the nested tags.


## Legend Settings in the Chart Series
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider ## Customizing Individual Items in the Chart Legend instead. Also would Styling fit better here?


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.

The structure of the nested tags is `<ChartSeriesLegend*Specifics*>`, where the specifics can be:

* `Markers`
* `Highlight`
* and others

>note Use the IntelliSense to explore the nested tags.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>note Use IntelliSense to explore the nested tags.


## Example

Customize the legend items by using nested tag settings.

````CSHTML
<TelerikChart>
<ChartSeriesItems>
<ChartSeries Type="ChartSeriesType.Column" Name="Product 1" Data="@series1Data">
<ChartSeriesLegendItem>
<ChartSeriesLegendItemMarkers Background="blue">
</ChartSeriesLegendItemMarkers>
</ChartSeriesLegendItem>
</ChartSeries>
<ChartSeries Type="ChartSeriesType.Column" Name="Product 2" Data="@series2Data">
<ChartSeriesLegendItem Type="@ChartLegendItemType.Area">
<ChartSeriesLegendItemMarkers Background="#00ff00">
</ChartSeriesLegendItemMarkers>
</ChartSeriesLegendItem>
</ChartSeries>
</ChartSeriesItems>

<ChartCategoryAxes>
<ChartCategoryAxis Categories="@xAxisItems"></ChartCategoryAxis>
</ChartCategoryAxes>

<ChartTitle Text="Quarterly revenue"></ChartTitle>

<ChartLegend Position="ChartLegendPosition.Right" Visible="true">
<ChartLegendTitle Text="Revenue per product"
Background="lightblue"
Color="black">
</ChartLegendTitle>
<ChartLegendItem>
<ChartLegendItemMarkers Type="@ChartSeriesMarkersType.Cross"
Background="#00ff00">
</ChartLegendItemMarkers>
</ChartLegendItem>
</ChartLegend>
</TelerikChart>

@code {
public List<object> series1Data = new List<object>() { 10, 2, 5, 6 };
public List<object> series2Data = new List<object>() { 5, 8, 2, 7 };
public string[] xAxisItems = new string[] { "Q1", "Q2", "Q3", "Q4" };
}
````

## See Also

[Live Chart Legend Customization Demo](https://demos.telerik.com/blazor-ui/chart/legend-customization)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there relevant links to the API that you can include?