简体   繁体   English

动态数据提供程序中没有数据的amcharts

[英]amcharts that have no data in dynamic data provider

Gracefully handle amcharts that have no data. 优雅地处理没有数据的amcharts。 I want know if my dataProvider empty. 我想知道我的dataProvider是否为空。 When amcharts draw default null. 当amcharts绘制时,默认为null。 How can I handle it dynamically? 如何动态处理?

var chart = AmCharts.makeChart("chartdiv", {
    "theme": "none",
    "type": "serial",
    "dataProvider": data,
    "valueAxes": [{
    "title": "Income in millions, USD"
}]

I want to know how to handle it when the data is empty. 我想知道当数据为空时如何处理它。

Handle it externally by checking if the dataset contains records before even rendering the chart. 在渲染图表之前,通过检查数据集是否包含记录来从外部进行处理。

if (data && data.length){
  var chart = AmCharts.makeChart("chartdiv", {
    "theme": "none",
    "type": "serial",
    "dataProvider": data,
    "valueAxes": [{
    "title": "Income in millions, USD"
  }]
} else {
   // display a message to the user that there is no data available
}

The AMCharts folks seemed to have neglected handling an empty data set being passed in. AMCharts人员似乎忽略了处理传入的空数据集。

Another option is to create a dummy data point that displays a label on the chart . 另一个选择是创建一个虚拟数据点,以在图表上显示标签 I haven't personally used this approach because I would rather just hide the graph entirely if it contains no data. 我没有亲自使用这种方法,因为如果它不包含任何数据,我宁愿将其完全隐藏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM