gpt4 book ai didi

javascript - Google Timeline 重叠时间表

转载 作者:行者123 更新时间:2023-11-29 21:57:28 26 4
gpt4 key购买 nike

我创建了一个时间表,有时连续有两个时间表。这不是问题,但我想在一行中重叠显示它们。

请看这个例子:

enter image description here

因此,较小的行应显示为较大行的一部分。

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 Timeline 重叠时间表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25680289/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com