I've got a list of dates/values
i like to display in a Google Charts: Line Chart.
data.addRows([
[new Date("2011-02-01T15:18:21+00:00"), 21.77],
[new Date("2011-03-01T15:18:59+00:00"), 20.96],
//[...],
[new Date("2011-12-01T07:54:15+00:00"), 17.04],
[new Date("2012-01-01T10:29:00+00:00"), 20.43],
[new Date("2012-02-01T08:03:00+00:00"), 22.51],
[new Date("2012-03-01T08:07:00+00:00"), 26.75],
//[...],
[new Date("2013-01-02T16:16:00+00:00"), 20.7],
[new Date("2013-02-03T13:51:00+00:00"), 24.41],
[new Date("2013-03-01T08:06:00+00:00"), 25.44],
//[...],
[new Date("2014-01-01T10:19:00+00:00"), 16.24],
[new Date("2014-02-01T10:16:00+00:00"), 19.13],
[new Date("2014-03-01T08:05:00+00:00"), 17.68],
[new Date("2014-04-01T08:11:00+00:00"), 10.97]
//[...],
This works fine, but i like to seperate the values by year e.g. one line per year to compare them. How can I set the x-axis
range without the year?
This is the result i like to achieve, this works only if i fake all years to be the same.
I believe that you desire a discrete axis. However each date is unique so the result is that each data point is a discrete point on the axis. So the trick is to force a continuous axis and fix with formatting. So you do this by creating a view with the first column being a numeric month. Fix the format by translating 0-11 months to tick values and forcing every one tick. Now you can preserve the dates in original value.
And by the way, this is how I do almost all of my charts: 1) Use the data table to sort the rows 2) use the data view to filter on rows and columns and generate derivative values. 3) Use options to finish and/or abstract the presentation of the information.
Working Example on jsFiddle
You can group data using the
google.visualization.data.group
function. This should work for your example:EDIT
I thought I'd leave my old answer, in case it could help anyone. The code for your specific use case is below and a link to jsFiddle. From what I can tell there's no easy way to get the month strings to display in correct order, only the month numbers. If you want the month strings to show up, you'll need to make another copy of the grouped table with a string value for the first column and covert the number to a string (Jan, Feb...).