Wednesday, 28 August 2019

Is there a way to center label in nested pie chart without using magic numbers as radius for Amchart v4?

My problem: i would like to find an automatic way to center labels in donut chart cells. In my case each cells contains an array of complex objects, what i want is to show the number of those objects.

See: enter image description here

Playing with radius, allowed me to find those values:

  • First layer: -28
  • Second layer: -20
  • Third layer: -10
  • Fourth layer: -8

I applied it as a quick fix but i don't like this solution, as it's fixed for 4 layers (what if I need to add an other layer ? etc....) and using "magic numbers" is unmaintenable...

Do you have a better solution ?

You can test it here: https://jsfiddle.net/aliz/gwz7om9e/

Line 40:

 pieSeries.labels.template.radius = am4core.percent(positionRadiusInPie);

Note: Using those attributes didn't work: "horizontalCenter", "VerticalCenter", "textAlign", "align".

EDIT: response to Bhavik Kalariya

This is what I get if I force one radius for all layers. enter image description here



from Is there a way to center label in nested pie chart without using magic numbers as radius for Amchart v4?

No comments:

Post a Comment