我有一个unix时间戳列表列表,值。像这样:
stream = [[1485936060000, 268623], [1485936180000, 268624], [1485936300000, 268626]]
我想创建一个行谷歌图表,其中unix时间戳将显示为实际日期。我尝试迭代流数组并将它们全部转换为Date对象,但它并没有真正起作用。它抛出了这个例外:
Uncaught Error: Type mismatch. Value Wed Feb 01 2017 09:01:00 GMT+0100 (Romance Standard Time) does not match type number in column index 0
Bellow是该函数的完整代码:
google.charts.load('current', {'packages':['line']});
google.charts.setOnLoadCallback(drawChart);
var stream = {{ stream }}
var maximum = {{ maximum }}
var minimum = {{ minimum }}
var unit = {{ unitlabel }}
function drawChart() {
var data = new google.visualization.DataTable(stream);
data.addColumn('number', 'Timestamp');
data.addColumn('number', 'Actual value');
for ( var i = 0; i < stream.length; i++ ) {
var d = new Date(+stream[i][0]);
stream[i][0] = d;
}
data.addRows(stream);
var options = {
width: 1500,
height: 500,
isStacked: false,
axes: {
y: {
all: {
kWh: {label: 'kWh'},
format: { pattern: 'decimal'},
range: {
max: maximum,
min: minimum
}
},
}
},
};
var chart = new google.charts.Line(document.getElementById('curve_chart'));
chart.draw(data, options);
}
帮助?
答案 0 :(得分:0)
您必须为列设置正确的数据类型。像错误一样,你正试图适应日期时间&#39;在&#39;数字&#39;
更改列数据类型
data.addColumn(&#39; datetime&#39;,&#39;时间戳&#39;);