Google时间轴重叠时间表

编程入门 行业动态 更新时间:2024-10-27 17:19:21
本文介绍了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] //将前一个结束日期设置为当前行的开始日期} } }

您可以在这里查看示例: jsfiddle/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: jsfiddle/9GbNP/33/

更多推荐

Google时间轴重叠时间表

本文发布于:2023-11-22 09:36:22,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间表   时间   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!