Articles in this section
Category / Section

How to Avoid Duplicate X-Axis Labels in Angular Stacking Bar Chart?

2 mins read

Description

This article shows how to render x-axis labels without duplicates when indexing is enabled in Angular Stacking Bar Charts.

Solution

If isIndexed is set to true, this will results in the repetition of axis labels. This behavior occurs because each x-value is rendered on the axis according to the index value of the dataSource.

To avoid duplicate X-axis labels in an Angular Stacking Bar Chart when indexing is enabled, the axisLabelRender event can be implemented. This event is triggered before the axis gets rendered, allowing to filter out the duplicate X-axis labels to ensure that each label is displayed only once.

Code-snippet:

The following example shows how to filter out duplicate labels in axisLabelRender event.

app.component.html

<ejs-chart (axisLabelRender)="axisLabelRender($event)">
</ejs-chart> 

app.component.ts

public axisLabelRender(args): void {
       if (args.axis.name === 'primaryXAxis') {
           const labels: string[] = args.text.split(',').map((label) => label.trim());
           const uniqueLabels: string[] = Array.from(new Set(labels)); 
           args.text = uniqueLabels.join(', ');
       }
}; 

The following screenshot illustrates the output of the above code snippet.

Stacking Bar.png

View Sample in Stackblitz

Conclusion

I hope you enjoyed learning on how to avoid duplicate X-axis labels in Angular Stacking Bar Chart.
You can refer to our Angular Charts feature tour page to know about its other groundbreaking feature representations 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 manipulate 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 comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied