gpt4 book ai didi

javascript - google.visualization.DataTable,日期未定义

转载 作者:行者123 更新时间:2023-12-02 18:26:49 25 4
gpt4 key购买 nike

考虑以下代码:

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

function drawChart() {
var data = google.visualization.DataTable();
data.addColumn('datetime', 'Time');
data.addColumn('number', 'Leads');
data.addRow([Date.parse("2013-08-17 10:12:18"), 0]);
data.addRow([Date.parse("2013-08-17 09:13:42"), 14]);
data.addRow([Date.parse("2013-08-17 10:00:05"), 15]);
data.addRow([Date.parse("2013-08-17 11:12:18"), 3]);
var options = {
title: 'Company Performance',
fontSize: '12px',
curveType: 'function',
pointSize: 5,
hAxis: {
title: 'Daily Report',
titleTextStyle: {
color: '#FF0000'
}
},
vAxis: {
title: 'Leads',
titleTextStyle: {
color: '#FF0000'
}
}
};

var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}

现在,上面的代码可以加载谷歌图表API,定义一个DataTable并生成一个LineChart图表,但事实并非如此。相反,我在尝试添加列时出现以下错误

TypeError: data is undefined #at this line --> data.addColumn('datetime', 'Time')

谁能告诉我我错过了什么?

最佳答案

您在创建 google.visualization.Datatable 的新对象时没有使用 new

 function drawChart() {
// var data = google.visualization.DataTable(); missed new keyword
var data = new google.visualization.DataTable();
//...
}

关于javascript - google.visualization.DataTable,日期未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18292257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com