API wrong date interpret (it add + 1 month on chart)

28 views
Skip to first unread message

Marcin Piotrowski

unread,
Aug 21, 2018, 12:08:24 PM8/21/18
to Google Visualization API

Hello,
I am faced with problem with date right now.
Please note last date in code is (2018, 08, 20) but on chart it is september (please find attached file).
Any idea why it is lakie that?

Whole code here :

google.charts.load('current', {packages: ['corechart', 'line', 'scatter']});
  google.charts.setOnLoadCallback(drawEBChart);

function drawEBChart() {
      var data = new google.visualization.DataTable();
      data.addColumn('date', 'Data');
      data.addColumn('number', 'Balance');
      data.addColumn('number', 'Equity');

      data.addRows([
[new Date(2018, 05, 16), 0.00, 0.00],  [new Date(2018, 05, 17), 0.00, 0.00],  [new Date(2018, 05, 18), 0.00, 0.00],  [new Date(2018, 05, 21), 0.00, 0.00],  [new Date(2018, 05, 22), 0.00, 0.00],  [new Date(2018, 05, 23), 0.00, 0.00],  [new Date(2018, 05, 24), 0.00, 0.00],  [new Date(2018, 05, 25), 0.00, 0.00],  [new Date(2018, 05, 28), 0.00, 0.00],  [new Date(2018, 05, 29), 0.00, 0.00],  [new Date(2018, 05, 30), 0.00, 0.00],  [new Date(2018, 05, 31), 0.00, 0.00],  [new Date(2018, 06, 01), 0.00, 0.00],  [new Date(2018, 06, 04), 0.00, -0.27],  [new Date(2018, 06, 05), 0.20, 0.20],  [new Date(2018, 06, 06), 0.20, 0.20],  [new Date(2018, 06, 07), 0.27, 0.27],  [new Date(2018, 06, 08), 0.32, 0.32],  [new Date(2018, 06, 11), 0.38, 0.38],  [new Date(2018, 06, 12), 0.41, 0.41],  [new Date(2018, 06, 13), 0.48, 0.48],  [new Date(2018, 06, 14), 0.54, -1.90],  [new Date(2018, 06, 15), 0.65, -7.71],  [new Date(2018, 06, 18), 0.99, -7.59],  [new Date(2018, 06, 19), 1.05, -12.52],  [new Date(2018, 06, 20), 1.16, -13.80],  [new Date(2018, 06, 21), 1.73, -13.24],  [new Date(2018, 06, 22), 2.16, -10.30],  [new Date(2018, 06, 25), 2.27, -12.60],  [new Date(2018, 06, 26), 2.25, -13.25],  [new Date(2018, 06, 27), 2.18, -15.13],  [new Date(2018, 06, 28), 2.28, -10.72],  [new Date(2018, 06, 29), 2.29, -7.41],  [new Date(2018, 07, 02), 2.34, -8.81],  [new Date(2018, 07, 03), 2.37, -7.19],  [new Date(2018, 07, 04), 2.44, -7.54],  [new Date(2018, 07, 05), 2.44, -6.96],  [new Date(2018, 07, 06), 2.62, -5.28],  [new Date(2018, 07, 09), 2.71, -2.97],  [new Date(2018, 07, 10), 2.84, -1.73],  [new Date(2018, 07, 11), 2.88, -1.53],  [new Date(2018, 07, 12), 2.85, -3.85],  [new Date(2018, 07, 13), 3.29, 0.46],  [new Date(2018, 07, 16), 3.42, 0.88],  [new Date(2018, 07, 17), 4.05, -2.61],  [new Date(2018, 07, 18), 4.48, -3.44],  [new Date(2018, 07, 19), 4.81, -9.37],  [new Date(2018, 07, 20), 2.24, -0.69],  [new Date(2018, 07, 23), 2.91, -0.83],  [new Date(2018, 07, 24), 2.94, -2.26],  [new Date(2018, 07, 25), 3.43, -4.58],  [new Date(2018, 07, 26), 3.57, -2.60],  [new Date(2018, 07, 27), 4.11, -4.43],  [new Date(2018, 07, 30), 4.41, -3.62],  [new Date(2018, 07, 31), 5.16, -18.14],  [new Date(2018, 08, 01), 5.45, -17.81],  [new Date(2018, 08, 02), 5.68, -16.59],  [new Date(2018, 08, 03), 5.69, -14.61],  [new Date(2018, 08, 06), 6.00, -14.64],  [new Date(2018, 08, 07), 6.54, -13.96],  [new Date(2018, 08, 08), 6.60, -12.01],  [new Date(2018, 08, 09), 6.86, -10.44],  [new Date(2018, 08, 10), 7.14, -8.21],  [new Date(2018, 08, 13), 7.18, -12.07],  [new Date(2018, 08, 14), 7.83, -8.19],  [new Date(2018, 08, 15), 7.91, -10.85],  [new Date(2018, 08, 16), 7.41, -5.27],  [new Date(2018, 08, 17), 6.90, -13.44],  [new Date(2018, 08, 20), 6.93, -23.59],       ]);

var formatter = new google.visualization.DateFormat({pattern: "dd-MM-yy"});
formatter.format(data, 0);
    var options = {
legend: 'bottom',
pointSize: 3,
chartArea:{
width:"90%",
height:"70%",
},
    hAxis: {
format: 'dd-MM-yy',
    },
vAxis: {
  format: '0',
  gridlines: {
count: 24,
  }
 
    },
     series: {
    0: { color: '#ff0000' },
            1: { color: '#ffcc00' },
//0: { pointShape: 'circle' },
//1: { pointShape: 'circle' },
        }
      };
      var chart = new google.visualization.LineChart(document.getElementById('EB_chart_div'));
      chart.draw(data, options);
    }

chart.png

Marcin Piotrowski

unread,
Aug 21, 2018, 12:12:00 PM8/21/18
to Google Visualization API

I hope that link works:

https://jsfiddle.net/xs7ytre3/3/

Daniel LaLiberte

unread,
Aug 21, 2018, 12:25:57 PM8/21/18
to Google Visualization API
Hi Marcin,

See the documentation on dates and times at https://developers.google.com/chart/interactive/docs/datesandtimes
and notice the "Important" note about months.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/2d8ee640-7784-4334-a311-a3288dd2db1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Marcin Piotrowski

unread,
Aug 21, 2018, 1:31:48 PM8/21/18
to Google Visualization API
That's it :)
Thank you very much.
It is great help
Reply all
Reply to author
Forward
0 new messages