问题描述
我正在使用谷歌可视化 API 在我的网站上绘制时间线图表.它工作得很好.但是有一件小事困扰着我.我想在图表区域显示一条垂直线来表示当前日期.请让我知道任何类型的解决方案.
Hi I am using google visualization api to draw a timeline chart in my website. It works just fine. But there is one little thing that is bothering me. I want to display a vertical line in the chart area to represent the current date. Please let me know any kind of solutions.
我的代码:
<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>
预期结果:绿线代表当前日期
Intended Result: Green Line represents current date
如果这是不可能的,请建议任何其他可以实现此目的的 API.
If this is not possible, please suggest any other API which can achieve this.
推荐答案
创建第一个任务来表示当前日期:
Create a first task to represent current date:
dataTable.addRows([
['', 'Hoy', new Date(2014,9,2), new Date(2014,9,2) ],
用 jQuery 创建一个函数来延长这个任务:
Create a function with jQuery to make this task longer:
function MarcarHoy (div, filas){
$('#'+div+' text:contains("Hoy")').css('font-size','11px').attr('fill','#A6373C').prev().first().attr('height',filas*41+'px').attr('width','1px').attr('y','0');
}
调用函数:
chart.draw(dataTable, options);
MarcarHoy('example1',23);
google.visualization.events.addListener(chart, 'onmouseover', function(obj) {
MarcarHoy('example1');
});
}
结果:
来源:Viviendo en la Era de la网络 2.0
这篇关于谷歌时间线可视化中的垂直参考线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!