amcharts - amCharts 带有值的自定义图例(正确的方法和对齐方式)
问题描述
我目前正在构建一个热图,其中包含 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;
解决方案
非常简单的答案,我只需要设置 valueLabels 文本,而不是将两者连接到图例标签文本中。现在正确对齐。
chart.legend.labels.template.text = "{name}";
chart.legend.valueLabels.template.text = "{value}";
推荐阅读
- flutter-layout - Flutter:尝试从另一个变量引用变量时,无法在字段初始化程序中访问“this”以读取“msgTextStyle”
- php - Laravel 验证消息数组索引从 0 开始
- crc - 在计算CRC时,如果余数变为0,是否应该将余数设置为某个值?
- javascript - 如何使用 React 测试库测试 HTML 内容
- node.js - 错误!TypeError:将循环结构转换为 JSON
- php - 如何使用选定的类别名称创造价值?
- android - 如何在android中解析带有未知键的json
- php - 如果数据库中没有提供时区,使用 php time() 函数会更好吗
- reactjs - 如何在本地 WiFi 上公开从 WSL 运行的服务器/网站/服务?
- plsql - 有人可以请告诉我有什么问题吗?ORACLE APEX 中的 PLSQL