Multiple Series within the Same domain

55 views
Skip to first unread message

Nash Reilly

unread,
Feb 13, 2013, 6:33:56 PM2/13/13
to google-visua...@googlegroups.com
Hi, I'm trying to figure out if it's even possible to post two series with the same domain, but different data points. Possible it's a little clearer if I show you the table for what I'm trying to do:

['Date1', 'Data1', 'Date2', 'Data2'],
['2/24/2012', 556, '5/12/2012', 734],
['5/7/2012', 4891, '6/16/2012', 999],
['5/28/2012', 987, '7/18/2012', 1023],
['9/5/2012', 1137, '12/16/2012', 3023]

Basically, I want the Date columns to fit to the domain axis, then correspond to the data in the similarly numbered data columns. I haven't figured out a way for Google Code to interpret the Date2 column as a domain series and not a data series; it just throws an error about dissimilar data typing. Any suggestions?

asgallant

unread,
Feb 13, 2013, 6:51:16 PM2/13/13
to google-visua...@googlegroups.com
You don't need to use a second domain series, but you will need to change to a "date" type axis:

var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Data1');
data.addColumn('number', 'Data2');
data.addRows([
    [new Date(2012, 1, 24), 556, null], // 2/24/2012
    [new Date(2012, 4, 7), 4891, null], // 5/7/2012
    [new Date(2012, 4, 12), null, 734], // 5/12/2012
    [new Date(2012, 4, 28), 987, null], // 5/28/2012
    [new Date(2012, 5, 16), null, 999], // 6/16/2012
    [new Date(2012, 6, 18), null, 1023], // 7/18/2012
    [new Date(2012, 8, 5), 1137, null], // 9/5/2012
    [new Date(2012, 11, 16), null, 3023] // 12/16/2012
]);

Nash Reilly

unread,
Feb 13, 2013, 6:54:30 PM2/13/13
to google-visua...@googlegroups.com
Thanks for the Javascript date tip; I'm using that in my code, I just wrote them out as strings for the purpose of clarity in this example. 

So it's just a matter of setting the values that don't show up on a given date as "null"?

asgallant

unread,
Feb 13, 2013, 6:57:41 PM2/13/13
to google-visua...@googlegroups.com
Mostly.  If you are drawing a Line or Area chart, you should also set the "interpolateNulls" option to true.

Nash Reilly

unread,
Feb 13, 2013, 7:01:32 PM2/13/13
to google-visua...@googlegroups.com
Awesome. Thank you so much for your help, this has been driving me nuts for almost a week.
Reply all
Reply to author
Forward
0 new messages