我创建了一个时间表,有时连续有两个时间表。这不是问题,但我想将它们显示在一行中并重叠。
请参阅此示例:
因此,较小的线应该显示为较大线的一部分。
Google 的可视化 API 非常棒,是一件非常好的事情,但它的文档还没有那么完善。
最佳答案
考虑到您已经对数据进行了排序,您可以执行以下操作:
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
}
}
}
您可以在此处查看示例:http://jsfiddle.net/9GbNP/33/
关于javascript - Google 时间轴重叠时间表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25680289/