0
votes

I've made a custom data source selector for the Google Chart Editor which has worked out wonderfully, but I'm running into an annoying little problem with the way the dates are represented on the continuous major axis of type date. For some reason, giving a date at the end of the year (e.g. new Date(2014,11,31,0,0,0)) gets labelled as the next year.

Here's a JSFiddle that describes the issue. I know I could just use a discrete axis and pass a string representation of the year, but my data source selector allows selecting a different interval (i.e. daily, monthly, weekly yearly) and a continuous axis is best for this.

Does anyone know why this happens, and is there a way to adjust how the API chooses labels for a continuous date axis?

1

1 Answers

0
votes

It's interesting how phrasing a question for others can make one think of an answer. I decided to try specifying the options.hAxis.ticks and although I pass the same dates, it does change the hAxis labels to what I expect.

See the JSFiddle

It's not the best solution, since I would rather have the hAxis ticks match the nearest data point, but it is functional.

Here are the options that I specified:

   var options = {
        title: 'Total Sales Value Per Year',
        hAxis: {
            title: 'Year End',
            ticks: [ 
                new Date(2010,11,31,0,0,0), 
                new Date(2011,11,31,0,0,0), 
                new Date(2012,11,31,0,0,0), 
                new Date(2013,11,31,0,0,0), 
                new Date(2014,11,31,0,0,0) 
            ]
        }
    };