amcharts / amcharts4

The most advanced amCharts charting library for JavaScript and TypeScript apps.
https://www.amcharts.com/
1.16k stars 322 forks source link

Add an extra label to a sunburst slice #4413

Closed diedel closed 1 month ago

diedel commented 3 months ago

Question

I have a sunburst with two levels and I would like to add the labels "0", "1" and "2" to each of its circunferences, like the ticks of radial axis. I have managed to do it with this ugly code:

var level0 = chart.seriesTemplates.create("0");
label0 = level0.createChild(am4core.Label);
label0.text = "0";
label0.fontSize = 15;
label0.fontWeight = "bold";
label0.isMeasured = false;
label0.x = -105;
label0.y = -120;

Is it possible to add a child label to the slice directly and position it nicely?

Environment (if applicable)

Additional context

Captura de pantalla 2024-08-05 150225

martynasma commented 3 months ago

How about adding a zero-value slices for each level?

They would not affect the general diagram, but you could use them for labels.

diedel commented 3 months ago

Nice idea @martynasma , thank you!

Captura de pantalla 2024-08-08 112137

I created one zero-value slice for each of the three levels. I display its labels outside of the slice and with "bent" and left padding (I tried to rotate the labels around the slice's arc but I didn't succeed)

    var level0 = chart.seriesTemplates.create("0");
    level0.labels.template.inside = false;
    level0.labels.template.fill = am4core.color("#000");
    level0.labels.template.text = "{category}";
    level0.labels.template.bent = true;
    level0.labels.template.paddingLeft = 10;
    level0.slices.template.tooltipText = "";
martynasma commented 3 months ago

Would you be able to post your whole chart and data on CodePen/jsFiddle so that we can test?

diedel commented 3 months ago

Here is the Pen:

https://codepen.io/diedel/pen/VwJBamV

martynasma commented 2 months ago

If you need those labels to not be drawn at an angle, you can just add this:

level0.labels.template.relativeRotation = false;
github-actions[bot] commented 1 month ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.