Articles in this section

How to Set Data Label Background Color in a JavaScript Pie Chart?

Description

This article explains how to set the background color for the data label based on a slice color in JavaScript Pie Charts.

Solution

Data labels are the texts or numbers that provide specific information about each data point in the pie chart. The background color for this data label can be applied based on the slice color by adding the slice colors in an array of strings and then applying the background color by using the color argument in the textRender event of the pie chart.

Code Snippet

var seriesColor = ['#00bdae', '#404041', '#357cd2', '#e56590', '#f8b883'];
var pie = new ej.charts.AccumulationChart({
    .......
    pointRender: pointRender,
    textRender: textRender,
});
pie.appendTo('#pie-container');
var textRender = function (args) {
args.color = seriesColor[args.point.index % 10];
};

The following image illustrates the output of the above code:

image.png

Refer to the working sample for additional details and implementation:View Sample in Stackblitz

Conclusion:

We hope you enjoyed learning How to set data label background color based on slice color in a JavaScript Pie Chart. For more features, visit our [Javascript Pie Charts feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Javascript Pie 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, BoldDesk support , 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)
Access denied
Access denied