Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove space between name and percentage in pie chart legend (amcharts4)

enter image description here

I want to get rid of that space in the legend between the name and the percentage. In the pic, I have highlighted the space in yellow.

For example, I want the first legend item to be "Lithuania (30.5%)". That extra space between "Lithuania" and "30.5%" spoils my UI.

My code for the legend is the following:

// Add and configure Series
var pieSeries = chart.series.push(new am4charts.PieSeries());
pieSeries.dataFields.value = "litres";
pieSeries.dataFields.category = "country";
pieSeries.slices.template.stroke = am4core.color("#fff");
pieSeries.slices.template.strokeWidth = 2;
pieSeries.slices.template.strokeOpacity = 1;
pieSeries.ticks.template.disabled = true;
pieSeries.labels.template.disabled = true;

// This creates initial animation
pieSeries.hiddenState.properties.opacity = 1;
pieSeries.hiddenState.properties.endAngle = -90;
pieSeries.hiddenState.properties.startAngle = -90;

pieSeries.legendSettings.labelText = '{category}';
pieSeries.legendSettings.valueText = null;
pieSeries.labels.template.text = "{category}: {value}";
pieSeries.slices.template.tooltipText = "{category}: {value}";

chart.legend = new am4charts.Legend();
chart.legend.fontSize = 5;
chart.legend.markers.template.width = 5;
chart.legend.markers.template.height = 5;

What change must I make in order to get this done?

like image 799
Thanatos Avatar asked Apr 07 '19 12:04

Thanatos


1 Answers

You can move the value to the "labelText":

pieSeries.legendSettings.labelText = "{category}: {value.percent.formatNumber('#.0')}%";

And disable value labels altogether:

chart.legend.valueLabels.template.disabled = true;
like image 180
martynasma Avatar answered Dec 15 '22 13:12

martynasma