amCharts带有值的自定义图例(正确的方法和对齐方式)

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

我目前正在构建一个热点地图,其中包含100多个数据点(国家/地区,值)。

我创建了一个自定义图例,仅显示前10个国家及其值。

但是无论如何对齐方式不正确(名称和值之间的错边和距离,是否有更好的方法?

chart.legend = new am4maps.Legend();
chart.legend.position = "right";
chart.legend.data = [];

for (let index = 0; index < 10; index++) {
    chart.legend.data.push({
        name: legend_data[index]['id'],
        fill: colorSet.next(),
        value: legend_data[index]['value']
    });
}

chart.legend.labels.template.text = "{name}: {value}%";
chart.legend.itemContainers.template.paddingTop = 2;
chart.legend.itemContainers.template.paddingBottom = 2;

enter image description here

amcharts
1个回答
0
投票

非常简单的答案,我只需要设置valueLabels文本,而不是将两者都连接到图例标签文本中。现在可以正确对齐。

chart.legend.labels.template.text = "{name}";
chart.legend.valueLabels.template.text = "{value}";
© www.soinside.com 2019 - 2024. All rights reserved.