删除饼图图例中名称和百分比之间的空格(amcharts4)

问题描述 投票:1回答:1

enter image description here

我想摆脱名称和百分比之间的图例中的空格。在图片中,我突出了黄色的空间。

例如,我希望第一个图例项为“立陶宛(30.5%)”。 “立陶宛”和“30.5%”之间的额外空间破坏了我的用户界面。

我的传奇代码如下:

// 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;

为了完成这项工作,我必须做出哪些改变?

legend pie-chart amcharts legend-properties amcharts4
1个回答
2
投票

您可以将值移动到"labelText"

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

并完全禁用值标签:

chart.legend.valueLabels.template.disabled = true;
© www.soinside.com 2019 - 2024. All rights reserved.