gpt4 book ai didi

javascript - AmCharts 4 处理空数据

转载 作者:行者123 更新时间:2023-12-01 01:26:16 26 4
gpt4 key购买 nike

我正在开发 AmCharts,我可以动态加载数据。有时,响应中可能会发送空数据。我需要处理 AmCharts4 中的空数据。 In this link I see the example for Amcharts3 handling null data

var chart = am4core.create("reason_for_failure", am4charts.PieChart);
// 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;

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

chart.data = [];

最佳答案

看起来他提供的示例代码或多或少直接来 self 们的饼图演示之一,例如Pie Chart With Legend ,所以我将其与 mirror GitHub issue 中的解决方案混合并匹配(演示链接位于底部)。

同样,beforevalidated event非常适合处理为 chart.data 分配空数组的情况,例如

chart.events.on("beforevalidated", function(event) {
// check if there's data
console.log(event.target.data.length);
if (event.target.data.length == 0) {
// handle null data here
}
});

它必须是 beforevalidated 事件,因为如果没有数据,beforedatavalidated 不会触发。

演示:

https://codepen.io/team/amcharts/pen/88d11b5385a2669319c1a0fcdaa1e199/

关于javascript - AmCharts 4 处理空数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53745343/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com