How to customize the legend area in the Angular Pie Chart?
Description
This article shows how to customize the legend area in the Pie Chart using Angular Charts.
Solution
A legend explains the significance of several series in a Chart. When there are more legends, you can enable the paging to the legends page by page. The arrow with numbers will be displayed in paging.
You can customize that paging to your preference by adding the annotations in the chart. Then you can use the chartMouseClick event to click on the annotation. Based on the target argument in the chartMouseClick event, you can change the legend height and annotation content. Then refresh the chart by using its refresh method.
Code Snippet
app.component.html
<ejs-accumulationchart (chartMouseClick)='mouseClick($event)' [annotations]='annotations'>
</ejs-accumulationchart>
app.component.ts
public annotations: ChartAnnotationSettingsModel[] = [
{
x: '80%',
y: '66%',
coordinateUnits: 'Pixel',
content: '<div id="annotation1" style="cursor:pointer">More...</div>'
}
];
public mouseClick(args: IMouseEventArgs): void {
if(args.target == "annotation1"){
if(document.getElementById("annotation1").innerHTML == "More..."){
this.pie.legendSettings.height = "240px";
this.pie.annotations[0].content = '<div id="annotations" style="cursor:pointer">Show Less...</div>'
this.pie.annotations[0].y = '78%';
}
else{
this.pie.legendSettings.height = "150px";
this.pie.annotations[0].content = '<div id="annotation1" style="cursor:pointer">More...</div>'
this.pie.annotations[0].y = '66%';
}
this.pie.refresh();
}
}
The following image illustrates the output of the above code.
Initial Rendering
After clicking on more annotation
Conclusion
I hope you enjoyed learning how to customize the legend area in the Angular Pie Chart.
You can refer to our Angular Charts feature tour page to learn about its other features and documentation, and how to quickly get started for configuration specifications. You can also explore our Angular Charts example to understand how to create and visualize data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comment section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!