Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using DateTime instead of Date in Google chart CandlestickChart

I'm trying to use datetime instead of date to build chart using the Google-chart API.

Based on the sample from Google (sample)

 var data = new google.visualization.DataTable();
    data.addColumn('date', 'Date');
    data.addColumn('number', 'Stock low');
    data.addColumn('number', 'Stock open');
    data.addColumn('number', 'Stock close');
    data.addColumn('number', 'Stock high');

 data.addRows([
                  [new Date(2008, 1 ,1), 1000, 1000, 1500, 2000],
                  [new Date(2008, 1 ,2), 500, 1000, 1500, 2500],
                  [new Date(2008, 1 ,3), 1000, 1000, 1500, 2000]
    ]);

I can play with dates, but I want to use date & hours, something like

data.addRows([
              [new Date(2008, 1 ,1, 00, 00, 00), 1000, 1000, 1500, 2000],
              [new Date(2008, 1 ,1, 01, 00, 00), 500, 1000, 1500, 2500],
              [new Date(2008, 1 ,1, 02, 00, 00), 1000, 1000, 1500, 2000]

]);

This give me the following output

Any idea ?

like image 725
Dax Avatar asked Apr 17 '12 08:04

Dax


2 Answers

To clarify Mark's answer, change your line

data.addColumn('date', 'Date');

to

data.addColumn('datetime', 'Time');

this seems to work for me.

like image 136
gatoatigrado Avatar answered Sep 22 '22 17:09

gatoatigrado


You want 'datetime', not 'date'.

like image 30
Mark Maxham Avatar answered Sep 22 '22 17:09

Mark Maxham