无法读取属性' DataTable'未定义的谷歌图表

时间:2018-05-21 11:32:51

标签: javascript jquery ajax charts google-visualization

我正在开发基于谷歌地图的报告系统,我想在谷歌图表上显示谷歌地图数据,如汽车时间和速度,这是我的代码:

function updatereport() {
  //alert("aaa");
  $.ajax({
    url: 'getreport.php',
    data: {
      yy: '18',
      mm: '05',
      dd: '17',
      hh: '18',
      driverid: '7'
    },
    type: 'get',
    error: function() {
      alert("some error ! :(");
    },
    success: function(result) {
      //alert(result);
      var myobj = JSON.parse(result);

      google.charts.load('visualization', {
        '1.0': ['corechart']
      });
      google.charts.setOnLoadCallback(drawChart(myobj));

    } //func 
  }) //ajax
}
// Draw the chart and set the chart values
function drawChart(myobj) {

  var data = new google.visualization.DataTable();
  alert("a");
  data.addColumn("number", "time");
  data.addColumn("number", "speed");
  data.addRow();
  for (i in myobj)
    data.addRows(myobj[i].time);


  //var xx=[['T', 'H'],[2, 8.2],[3, .2],[4, 4],[6, 2],[9, 8]];
  //var data = google.visualization.arrayToDataTable(xx);
  //alert(myobj[1].time);
  // Optional; add a title and set the width and height of the chart
  var options = {
    'title': 'My Average Day',
    'width': 550,
    'height': 400
  };

  // Display the chart inside the <div> element with id="piechart"
  var chart = new google.visualization.LineChart(document.getElementById('chart'));
  chart.draw(data, options);
}


但问题是当我运行此代码时显示

  

无法读取属性&#39; DataTable&#39;未定义的

1 个答案:

答案 0 :(得分:0)

load语句看起来不正确,

替换这个...

configuration.urlCache?.removeAllCachedResponses()

有了......

  google.charts.load('visualization', {
    '1.0': ['corechart']
  });