Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Chart - two date series on the same chart

I have data about earnings occurred on some dates:

['2013-02-13',100],['2013-03-20',200],['2013-04-11',160]

and data about costs occurred on some other dates:

['2013-02-22',60],['2013-03-04',90],['2013-03-25',110]

So X-axis is continuous one (date), and Y-axis represents earning/cost values (number). I'd like to represent these two date-value series on the same chart. They share the same timeline but events occurred on different dates?

Is this possible?

like image 597
sbrbot Avatar asked Aug 03 '13 22:08

sbrbot


1 Answers

Yes, you just need to join the two data sets, using the google.visualization.data.join method:

var joinedData = google.visualization.data.join(data1, data2, 'full', [[0, 0]], [1], [1]);

If you draw a chart using this method, you will have two series of data that can be charted together. See this example: http://jsfiddle.net/asgallant/XF7JE/

Incidentally, with your dates input like that, you will get a discrete axis, not a continuous axis. You need to input the dates as javascript Date objects to get a continuous axis.

like image 108
asgallant Avatar answered Dec 10 '22 03:12

asgallant