Years format

18 views
Skip to first unread message

Sergey Cherepnin

unread,
Apr 14, 2023, 8:53:16 AM4/14/23
to Google Visualization API
Hello,

I found that if I use "date" format and custom format like:
 hAxis.format: 'MM dd YYYY',

there is bug that dates starting from Dec 26 2021 are displayed as Dec 26 2022.

If I use format: 'MM dd yyyy' - everything works good. 

YYYY - not documented, but works, so it confuses and could lead to such bugs.

Example:

      var data = new google.visualization.DataTable();
      data.addColumn('date', 'Date');
      data.addColumn('number', 'Dogs');

      data.addRows([
        [new Date(2021,11,25), 0],   [new Date(2021,11,26), 10], [new Date(2021,11,27), 5]
      ]);

      var options = {
        hAxis: {
          title: 'Time',
          format: 'MM dd YYYY', // <--------------- !!! should be yyyy
        },
        vAxis: {
          title: 'Popularity'
        },
        backgroundColor: '#f1f8e9'
      };

      var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
      chart.draw(data, options);
Reply all
Reply to author
Forward
0 new messages