Articles in this section
Category / Section

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

2 mins read

Description

This article shows how to set the background color for the datalabel 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 string and then apply 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

View Sample in Stackblitz

Conclusion:

We hope you found this guide helpful in 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, support portal, 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