# Legend

The Telerik UI for ASP.NET MVC Chart supports customization of its legend, which displays the name of the configured data series.

> * Series without a specified name will not display legend items.
> * To render a legend item for the Pie, Donut, and Funnel series, set the [`categoryField`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/chartserieslegenditemsettingsbuilder) of the items.

## Configuring the Legend Items

The legend item types and settings are derived from the series configuration.

To customize the legend, use the [`Legend`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/chartbuilder#legendsystemaction) configuration option.

The following example shows how to customize the Legend Item of a given series:

```Razor HtmlHelper
        .Series(series =>
        {
            series.Line(new double[] { 4.54, 3.32, 2.71 }).Name("World")
            .LegendItem(li => li
                .Markers(m => m.Type(ChartMarkerShape.Triangle))
                .Type("line")
                .Area(a => a.Opacity(0.5))
                .Highlight(h => h.Visible(true).Markers(hm => hm.Type(ChartMarkerShape.Rect))));
```

You can also configure the legend items for all series. The following example shows how to do that:

```Razor HtmlHelper
        .SeriesDefaults(sd => sd.Line()
                .LegendItem(li => li
                .Markers(m => m.Type(ChartMarkerShape.Triangle))
                .Type("line")
                .Area(a => a.Opacity(0.5)))
```

## Positioning and Orientation

To control the position of the legend, use any of the following supported `Position` values:

* `"Top"`
* `"Bottom"`
* `"Left"`
* `"Right"`
* `"Custom"`

The following example demonstrates how to configure the position and orientation of the Chart legend.

```Razor HtmlHelper
    @(Html.Kendo().Chart()
        .Name("chart")
        .Legend(legend => legend
            .Position(ChartLegendPosition.Bottom)
            .Orientation(ChartLegendOrientation.Horizontal)
        )
        // Other options.
    )
```

To customize the position of the legend, use the `offsetX` and `offsetY` options.

![UI for ASP.NET MVC Chart custom legend position](https://www.telerik.com/aspnet-mvc/documentation/assets/7aec60c34fadcc78132b962a0c1d82f1/chart-legend-custom-position.png)

```Razor HtmlHelper
    @(Html.Kendo().Chart()
        .Name("chart")
        .Legend(legend => legend.Position(ChartLegendPosition.Custom).OffsetX(500).OffsetY(200))
        // Other options.
    )
```

## Showing and Hiding

If you set the series names, the Chart displays a default legend.

The following example demonstrates how to hide the legend by setting its `Visible` option to `false`.

```Razor HtmlHelper
     @(Html.Kendo().Chart()
        .Name("chart")
        .Legend(legend => legend
            .Visible(false)
        )
        // Other options.
    )
```

## Hiding a Series from the Legend

To exclude series from the legend, set their `VisibleInLegend` option to `false`.

```Razor HtmlHelper
    @(Html.Kendo().Chart()
        .Name("chart")
        .Legend(legend => legend.Position(ChartLegendPosition.Top))
        .Series(series =>
        {
            series.Bar(new double[] { 56000, 63000, 74000, 91000, 117000, 138000 }).Name("Total Visits").VisibleInLegend(false);
            series.Bar(new double[] { 52000, 34000, 23000, 48000, 67000, 83000 }).Name("Unique visitors");
        })
        // Other options.
    )
```

## Setting a Title

You can configure the legend section of the Chart to render a title with customizable layout and content.

To define a title, configure the [`Title`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/chartlegendbuilder#titlesystemaction) property of the `Legend` configuration.

```Razor HtmlHelper
    @(Html.Kendo().Chart()
        .Name("chart")
       .Legend(legend => legend
              .Title(title=>title.Text("Series")
        )
        // Other options.
    )
```

## See Also

* [Using the API of the Chart HtmlHelper for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/chart-api/index)
* [Basic Usage of the Area Chart for ASP.NET MVC (Demos)](https://demos.telerik.com/aspnet-mvc/area-charts/index)
* [Server-Side API of the Chart for ASP.NET MVC](https://www.telerik.com/aspnet-mvc/documentation/api/chart)
