Reputation: 5671
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.
Upvotes: 2
Views: 1860
Reputation: 16068
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/
Upvotes: 3