我正在尝试绘制ComboChart
。我的问题是图表会在值之间不断添加日期,这使得图表不必要大:
我的代码:
var chart;
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawVisualization);
function drawVisualization() {
var graphData = [{"date":new Date(1470903103000),"count1":47,"count2":3},
{"date":new Date(1472134276000),"count1":92,"count2":20},
{"date":new Date(1472198154000),"count1":92,"count2":15}];
rowCount = graphData !== undefined ? graphData.length : 0;
var data = new google.visualization.DataTable();
data.addColumn('datetime', 'Date');
data.addColumn('number', 'Count1');
data.addColumn("number", "Count2");
for (var i = 0; i < rowCount; i++) {
var gDate = graphData[i].date;
var gCount1 = graphData[i].count1;
var gCount2 = graphData[i].count2;
data.addRow([ gDate, gCount1, gCount2]);
}
var options = {
title : 'Overview',
vAxis: {title: 'Count'},
hAxis: {title: 'Date'},
seriesType: 'bars',
series: { 1: { type: 'line' } },
//chartArea: { left: 0, top: 0, width: "80%", height: "80%" },
height: 200,
width: 500
};
chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
答案 0 :(得分:0)
解决方案非常简单,我只需要发送string
而不是dateTime
:
data.addColumn('datetime', 'Date');
=> data.addColumn('string', 'Date');
和var gDate = graphData[i].date;
=> var gDate = graphData[i].date.toString();