How to Change Series Data on Chart Legend Click in Angular Chart?
This article explains how to dynamically update the data source of a specific series in one chart when a legend item is clicked in another chart in Angular Chart.
When a legend item is clicked, the legendClick event provides the legend text and the corresponding data points. You can use this information to update the data source of a series in another chart instance.
Code Example
app.component.html
<ejs-chart #chart (legendClick)='legendClick($event)'>
<e-series-collection>
<e-series [dataSource]='data' type='Column' xName='x' yName='y' name='Gold' width=2 [marker]='marker'> </e-series>
<e-series [dataSource]='data1' type='Column' xName='x' yName='y' name='Silver' width=2 [marker]='marker'> </e-series>
<e-series [dataSource]='data2' type='Column' xName='x' yName='y' name='Bronze' width=2 [marker]='marker'> </e-series>
</e-series-collection>
</ejs-chart>
<ejs-chart #chart1>
<e-series-collection>
<e-series [dataSource]='data2' type='Column' xName='x' yName='y' name='Gold' width=2 [marker]='marker'> </e-series>
<e-series [dataSource]='data' type='Column' xName='x' yName='y' name='Silver' width=2 [marker]='marker'> </e-series>
<e-series [dataSource]='data1' type='Column' xName='x' yName='y' name='Bronze' width=2 [marker]='marker'> </e-series>
</e-series-collection>
</ejs-chart>
app.component.ts
public legendClick(args: ILegendClickEventArgs): void {
if (args.legendText == 'Gold')
this.chart1.series[0].dataSource = args.points;
}
Screenshot
Before Legend Click
After Legend Click
Sample
Conclusion
I hope you enjoyed learning about how to change series data on Chart legend click in Angular Chart.
You can refer to our Angular Chart’s feature tour page to learn about its other groundbreaking feature representations. You can also explore our Angular Chart Documentation to understand how to present and manipulate data.
For current customers, you can check out our Angular components on the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to explore our Angular Chart and other Angular components.
If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our support forums, Direct-Trac or feedback portal, or the feedback portal. We are always happy to assist you!