Google时间轴重叠时间表 [英] Google Timeline overlapping timesheets
本文介绍了Google时间轴重叠时间表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个时间表,有时连续有两个时间表。这不是问题,但是我想用重叠的方式将它们显示在一行中。
请参阅此示例:
所以应该将较少的行显示为较大行的一部分。
Google的可视化API非常棒,是一件非常好的事情,但目前还没有很好的记录。 / b>
解决方案
考虑到您已经对数据进行了排序,您可以这样做:
var data = [
['George Washington',new Date(1779,3,29),new Date(1790,2,3)],
['乔治华盛顿',新日期(1789,3,29),新日期(1797,2,3)],
['约翰亚当斯',新日期(1797年2月3日),新日期(1801,2,3)],
['Thomas Jefferson',新日期(1801,2,3),新日期(1809,2,3)],
] ; (数据[i-1] [0] ==数据[i])的每一行
为
(var i = 1; i< data.length; i ++) [0]){//如果前一个具有相同的标签
if(data [i-1] [2]> data [i] [1]){//如果上一个结束日期更长比当前行的开始日期
data [i-1] [2] = data [i] [1] //将前一个结束日期设置为当前行的开始日期
}
}
}
您可以在这里查看示例: http://jsfiddle.net/9GbNP/33/
I have created a timeline and sometimes there are two timesheets in a row. It is not a problem, but I would like to show them in one line with overlap.
Please see this example:
So the less line should be shown as a part of the bigger line.
Google's Visualization API is amazing, a very good thing, but it is not so well documented yet.
解决方案
Considering you already had your data sorted, you could do something like this:
var data=[
['George Washington', new Date(1779, 3, 29), new Date(1790, 2, 3)],
['George Washington', new Date(1789, 3, 29), new Date(1797, 2, 3)],
['John Adams', new Date(1797, 2, 3), new Date(1801, 2, 3)],
['Thomas Jefferson', new Date(1801, 2, 3), new Date(1809, 2, 3)],
];
for(var i=1;i<data.length;i++){ // for each row
if(data[i-1][0]==data[i][0]){ //if the previous one has the same label
if(data[i-1][2] > data[i] [1]){ // if the previous end date is greater than the start date of current row
data[i-1][2]=data[i] [1] // set the previous end date to the start date of current row
}
}
}
You can view an example here: http://jsfiddle.net/9GbNP/33/
这篇关于Google时间轴重叠时间表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文