[英]AmCharts 4 handling null data
I am working on AmCharts where I load data dynamically. 我正在AmCharts上工作,可以动态加载数据。 Sometimes, there may be null data sent from the response.
有时,响应中可能会发送空数据。 I need to handle null data in AmCharts4.
我需要在AmCharts4中处理空数据。 In this link I see the example for Amcharts3 handling null data
在此链接中,我看到了Amcharts3处理空数据的示例
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 = [];
It looks like the sample code he provided is more/less straight out of one of our Pie Chart demos, eg Pie Chart With Legend , so I mixed and matched that with the solution in the mirror GitHub issue (demo link on the bottom). 看起来他提供的示例代码与我们的饼图演示中的一个或多或少直接匹配,例如Pie Legend with Legend ,所以我将其与镜像GitHub问题 (底部的演示链接)中的解决方案进行了混合和匹配。
Again, the beforevalidated
event is perfect for handling the case of the chart.data
being assigned an empty array, eg 同样,
beforevalidated
事件非常适合处理为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
}
});
It would have to be the beforevalidated
event, because if there's no data, beforedatavalidated
does not trigger. 它必须是
beforevalidated
事件,因为如果没有数据, beforedatavalidated
不会触发。
Demo: 演示:
https://codepen.io/team/amcharts/pen/88d11b5385a2669319c1a0fcdaa1e199/ https://codepen.io/team/amcharts/pen/88d11b5385a2669319c1a0fcdaa1e199/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.