I've made a timeline chart, where I dont get to use specific dates/times, but I get value in minutes. Thats why I changed an example from type 'date' to 'number', and I multiply my value by 60000 (# of miliseconds in a minute).
http://jsfiddle.net/6M2sH/606/获取元素
google.load("visualization", "1", {packages:["timeline"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var container = document.getElementById('timeline');
var chart = new google.visualization.Timeline(container);
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: 'string', id: 'President' });
dataTable.addColumn({ type: 'number', id: 'Start' });
dataTable.addColumn({ type: 'number', id: 'End' });
dataTable.addRows([
[ 'Value1', 0*60000, 10*60000 ],
[ 'Value2', 10*60000, 15*60000 ],
[ 'Value1', 45*60000, 61*60000 ],
[ 'Value4', 15*60000, 45*60000 ],
[ 'Value3', 45*60000, 450*60000 ],
[ 'Value4', 375*60000, 450*60000 ],
]);
chart.draw(dataTable);
}
这个例子几乎是合适的,除了时间轴由于某种原因从凌晨1点开始。我希望它是0:00。
如何设置开始日期?
答案 0 :(得分:1)
实际上你必须在这种情况下使用 DATE 类型; 如果你可以使用 x * 60 * 60 给你秒。
如果你使用 x * 60 给你分钟,然后你可以把它插入任何你想要的地方;
对于插入秒,请使用new Date(0,0,0,0,0,yourSecond)
对于插入分钟,请使用new Date(0,0,0,0,yourMinutes,0)
dataTable.addColumn({ type: 'string', id: 'President' });
dataTable.addColumn({ type: 'date', id: 'Start' });
dataTable.addColumn({ type: 'date', id: 'End' });
dataTable.addRows([
[ 'Value1', new Date(0,0,0,0,0,0*60*60), new Date(0,0,0,0,0,1*60*60) ],
[ 'Value2', new Date(0,0,0,0,0,1*60*60), new Date(0,0,0,0,0,1.5*60*60) ]
]);