无法填充Google Graph Line Chart

时间:2015-12-30 23:16:27

标签: javascript google-api

以下是我填充它的方法,但它不起作用:

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);
打印时

newData值如下:

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

它没有显示错误,也没有显示图表。上面的代码可能有什么问题?

1 个答案:

答案 0 :(得分:0)

R> testdate <- 16716
R> class(testdate) <- "Date"
R> testdate
[1] "2015-10-08"

因此,由于您只有2列,您可以完全摆脱第3次开支。