javascript - Google 时间轴重叠时间表

标签 javascript php google-visualization

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

请参阅此示例:

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

相关文章:

javascript - Chrome 中未删除 session cookie 的解决方法

javascript - 一旦浏览器被重定向到另一个 URL,Chrome 是否会取消待处理的 Ajax 请求?

php - 打印没有附加内容(URL、日期等)的 HTML 页面

php - 来自 php mysql 的数组值的总和

php - Mysql 分隔符在 mysql 中有效,但在 PHP 中无效

javascript - Phantomjs 有效但速度很慢

Javascript 过滤函数可过滤掉虚假值

javascript - Google Charts 如何隐藏值 = 0

jquery - 使用 AJAX/Jquery 使用 MongoDB 投影填充 Google Chart

javascript - 无法使用 onclick 函数将选择标签上的值添加到谷歌图表数据表