无法填充Google Graph折线图



以下是我如何填充它,但它不起作用:

var data = new google.visualization.DataTable();
          var newData =[];
          for(var j = 0; j<dates.length;j++){
                newData.push([dates[j],close[j]]);
                document.write(newData[j] + "<br>");
              }
        // determine the number of rows and columns.
        var numRows = newData.length;
        var numCols = newData[0].length;
        data.addColumn('number', 'Date');
        data.addColumn('number', 'Close');      
          // now add the rows.
          for (var j = 0; j < numRows; j++){
              data.addRow(newData[j]);
          }

          var options = {
            hAxis: {
              title: 'Date'
            },
            vAxis: {
              title: 'Closing Price'
            },
            backgroundColor: '#f1f8e9'
          };
          var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
          chart.draw(data, options);

new打印出来的数据值如下:

20151229,108.74
20151228,106.82
20151224,108.03
20151223,108.61
20151222,107.23

它没有显示任何错误,也没有显示任何图形。上面的代码可能有什么错误?

function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Year', 'Sales', 'Expenses'],
      ['2004',  1000,      400],
      ['2005',  1170,      460],
      ['2006',  660,       1120],
      ['2007',  1030,      540]
    ]);
    var options = {
      title: 'Company Performance',
      curveType: 'function',
      legend: { position: 'bottom' }
    };
    var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
    chart.draw(data, options);
  }

因此,由于你只有2列,你可以完全摆脱第三项支出。

相关内容

  • 没有找到相关文章

最新更新