【发布时间】:2014-02-19 06:37:26
【问题描述】:
您好,我正在使用谷歌可视化 api 在我的网站上绘制时间线图。它工作得很好。但是有一件小事困扰着我。我想在图表区域显示一条垂直线来表示当前日期。请让我知道任何类型的解决方案。
我的代码:
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['timeline']}]}"></script>
<script type="text/javascript">
google.setOnLoadCallback(drawChart);
function drawChart() {
var container = document.getElementById('example3.1');
var chart = new google.visualization.Timeline(container);
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: 'string', id: 'Position' });
dataTable.addColumn({ type: 'string', id: 'Name' });
dataTable.addColumn({ type: 'date', id: 'Start' });
dataTable.addColumn({ type: 'date', id: 'End' });
dataTable.addRows([
[ 'President', 'George Washington', new Date(2014, 3, 29), new Date(2014, 4, 3)],
[ 'President', 'John Adams', new Date(2014, 2, 3), new Date(2014, 3, 3)],
[ 'President', 'Thomas Jefferson', new Date(2014, 2, 3), new Date(2014, 5, 3)],
[ 'Vice President', 'John Adams', new Date(2014, 3, 20), new Date(2014, 5, 3)],
[ 'Vice President', 'Thomas Jefferson', new Date(2014, 2, 3), new Date(2014, 6, 3)],
[ 'Vice President', 'Aaron Burr', new Date(2014, 2, 3), new Date(2014, 2, 3)],
[ 'Vice President', 'George Clinton', new Date(2014, 2, 3), new Date(2014, 2, 19)],
]);
chart.draw(dataTable);
}
</script>
<div id="example3.1" style="width: 1000px; height: 200px;"></div>
预期结果:绿线代表当前日期
编辑:
如果这不可行,请建议任何其他可以实现此目的的 API。
【问题讨论】:
-
感谢大家的宝贵意见,即使在 2 年后也是如此。从长远来看,这将帮助很多人。
标签: google-api google-visualization