Google图表-没有可用数据-可以显示空白图表吗? [英] Google Charts - No data available - Able to display a blank chart?

查看:166
本文介绍了Google图表-没有可用数据-可以显示空白图表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的数据数组看起来像这样,如何让Google图表仍然显示折线图?
[[日期,行]]

How can I still have Google Charts still show a line chart if my data array looks like this? [['Date','Line']]

即仅定义了轴。我的大多数图表都已导入数据,但有些图表上没有数据。我想显示一个空白图表。在上面的数据中,我收到一条错误消息而不是图表。

i.e. just the axis are defined. Most of my charts have data imported but some have nil on the data. I would like to display a blank chart. With data above I get an error message instead of a chart.

这是我认为的代码

google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);

function drawChart() {
  var data = google.visualization.arrayToDataTable(#{@visiting_spread_movement_array});

  var options = {
                 title: 'Point Spread Movements for #{@event.visiting_team}'
                };


  var chart = new google.visualization.LineChart(document.getElementById('show-spread-visiting'));

  chart.draw(data, options);

}


推荐答案

要绘制图表,您至少需要一个数据点。要对此进行归档,可以使用以下变通方法:

Well, to draw the chart you need at least one data point. To archieve this, you could use this workaround:

      var data = google.visualization.arrayToDataTable([
          [{
              f: 'Date',
              type: 'date' // wont work whithout this
          }, {
              f: 'Line',
              type: 'number' // wont work whithout this
          }], ]);

      var options = {
          title: 'Company Performance'
      };

      if (data.getNumberOfRows() == 0) { // if you have no data, add a data point and make the series transparent
          data.addRow([new Date(), 0])
          options.series = {
              0: {
                  color: 'transparent'
              }
          }
      }

完整小提琴: http: //jsfiddle.net/qaLgh955/

这篇关于Google图表-没有可用数据-可以显示空白图表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆