谷歌图表addcolumn不工作

时间:2014-02-09 15:54:20

标签: javascript google-visualization

请参阅下面的代码,我使用内联表并转换为添加列并添加行,以便我可以指定列类型 - 此代码不会显示任何错误或渲染图表...出了什么问题 - 提前感谢

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", '1.1', {packages:['corechart', 'annotationchart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
    var data = google.visualization.DataTable();
    data.addColumn('datetime', 'TimeStamp');
    data.addColumn('number', 'Temp(F)');
    data.addColumn('number', 'pH');
    data.addRows([ 
        [new Date(2014,02,04,15,15,14), 58.75, 7.97],
        [new Date(2014,02,04,15,15,19), 58.78, 7.93],
        [new Date(2014,02,04,15,23,08), 58.69, 7.94],
        [new Date(2014,02,04,20,49,46), 58.10, 7.94],
        [new Date(2014,02,04,21,14,15), 57.99, 7.92],
        [new Date(2014,02,04,21,15,05), 57.99, 7.92]
    ]);

    var options = {
        title: 'Temperature compensated pH',
        curveType: "function",
        hAxis: {format: 'e hh:mm:ss a'},     
        vAxes: {0: {logScale: false, minValue: 40}, 1: {logScale: false}},
        series: {0: {targetAxisIndex: 0}, 1: {targetAxisIndex: 1}}
    };

    var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div'));
    chart.draw(data, options);
}
</script>
</head>
<body>
<h1>pH Logger</h1>
<hr>
<div id="chart_div" style="width: 900px; height: 500px;"></div>

1 个答案:

答案 0 :(得分:1)

new构造函数调用之前,您缺少google.visualization.DataTable()关键字:

var data = new google.visualization.DataTable();