# Implementing External Legend in KendoReact Chart

## Environment

<table>
	<tbody>
		<tr>
			<td>Product Version</td>
			<td>9.0.0</td>
		</tr>
		<tr>
			<td>Product</td>
			<td>Progress® KendoReact Chart</td>
		</tr>
	</tbody>
</table>

## Description

I want to move the `ChartLegend` outside the `Chart` and link the `ChartSeries` to it.

This KB article also answers the following questions:

* How do I create an external legend in KendoReact Chart?
* Can I link ChartSeries to an external ChartLegend in KendoReact?
* How to set up an external legend for KendoReact Chart?

## Solution

To implement an external legend for the KendoReact Chart, follow these steps:

1. Create a KendoReact chart
2. Create an html element that represents the layout of the needed external legend and map it to the chart series data:

```javascript
<div>
    <h5>Legend</h5>
    {series.map((item, idx) => {
        return (
            <p
                key={idx}
                style={{ color: item.color, opacity: item.visible ? 1 : 0.5 }}
                onClick={(e) => handleLegendItemClick(e, item)}
            >
                {item.name}
            </p>
        );
    })}
</div>
```

3. Attach a click handler to the created legend items in order to update the visibility other the chart series on each external legend item click:

```javascript
const handleLegendItemClick = (e, seriesItem) => {
    let newSeries = series.map((item) => {
        if (item.name === seriesItem.name) {
            item.visible = !item.visible;
        }
        return item;
    });
    setSeries(newSeries);
};
```

You can test the described approach here:

[Demo Source](https://demos.telerik.com/kendo-react-ui/knowledge-base/charts/external-legend/source.txt)

## See Also

* [KendoReact Chart Documentation](https://www.telerik.com/kendo-react-ui/components/charts/)
* [KendoReact ChartSeriesItem API](https://www.telerik.com/kendo-react-ui/components/charts/api/ChartSeriesItem/)
* [KendoReact ChartLegend API](https://www.telerik.com/kendo-react-ui/components/charts/api/ChartLegend/)
