1 回答
TA贡献1765条经验 获得超5个赞
似乎 amCharts 默认情况下为工具提示设置相同的颜色,即使设置了自定义工具提示 HTML:
/**
* ---------------------------------------
* This demo was created using amCharts 4.
*
* For more information visit:
* https://www.amcharts.com/
*
* Documentation is available at:
* https://www.amcharts.com/docs/v4/
* ---------------------------------------
*/
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.PieChart);
// Add data
chart.data = [{
"country": "Lithuania",
"litres": 501.9,
"color": am4core.color("#ED1C24")
}, {
"country": "Czechia",
"litres": 301.9,
"color": am4core.color("#235789")
}, {
"country": "Ireland",
"litres": 201.1,
"color": am4core.color("#F1D302")
}, {
"country": "Germany",
"litres": 165.8,
"color": am4core.color("#020100")
}];
// Add and configure Series
var pieSeries = chart.series.push(new am4charts.PieSeries());
pieSeries.dataFields.value = "litres";
pieSeries.dataFields.category = "country";
pieSeries.slices.template.propertyFields.fill = "color";
pieSeries.slices.template.tooltipHTML = "<p>My custom tooltip color: {color}</p>"
chart.legend = new am4charts.Legend();
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
#chartdiv {
width: 100%;
height: 400px;
}
<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>
<div id="chartdiv"></div>
(基于此 amCharts 演示的示例)
无论是使用自定义颜色还是通过删除此行来使用主题颜色,这都适用:
pieSeries.slices.template.propertyFields.fill = "color";
因此,这个属性可能在代码中的其他地方被覆盖。您可以通过添加此行来强制工具提示具有相同的填充颜色:
chart.tooltip.getFillFromObject = true;
编辑:颜色也可以通过工具提示 HTML 访问"{color}"
,以便它可以在样式属性中使用,例如。
添加回答
举报