Stacked BarChart with Date HAxis

32 views
Skip to first unread message

Jeremiah Mitchell

unread,
Jun 26, 2013, 11:31:45 AM6/26/13
to google-visua...@googlegroups.com
All -

I'm trying to create a gantt type chart that uses dates but the hAxis is going backwards to 1950 and forwards to 2125.

Here is the sample:

function drawVisualization({
  var data new google.visualization.DataTable();
  data.addColumn('string''Name');
  data.addColumn('date''start');
  data.addColumn('date''1');
  data.addColumn('date''2');
  data.addColumn('date''3');
  data.addColumn('date''4');

  data.addRow(['First'new Date(201311)new Date(201321)new Date(201341)nullnull]);
  data.addRow(['Second'new Date(201321)nullnullnew Date(201321)new Date(201391)]);

  new google.visualization.BarChart(document.getElementById('visualization')).
      draw(data,
           {title:"Example broken XAxis",
            width:1600height:400,
            vAxis{title"Project"},
            hAxis{title"Date"}isStackedtrue,
           series{
            0{
                visibleInLegendfalse,
                color'transparent'
            }
        }}
      );
}


Any ideas if this is possible?  If so what am I doing wrong?

asgallant

unread,
Jun 26, 2013, 12:24:18 PM6/26/13
to google-visua...@googlegroups.com
Using dates for the hAxis of a BarChart doesn't work well, as you can see.  I think that the charts are trying to interpret the date as a number to draw the bar, and when you stack the dates like that, you get a chart with bars equivalent to the stacked numbers.  If you make the first series visible, you will see that it starts on 1970 (the start of the Unix epoch), and draws a bar equivalent to the number of milliseconds of the date value, then stacks the next date-equivalent milliseconds on top.

Using a BarChart for this is the wrong way to go, especially since the new Timelines are available on the RC version (1.1).  Try this: http://jsfiddle.net/asgallant/Vsf3t/

Jeremiah Mitchell

unread,
Jun 26, 2013, 12:28:26 PM6/26/13
to google-visua...@googlegroups.com
Thanks, I'll give that a try.

No idea how I missed the timelines type.

asgallant

unread,
Jun 26, 2013, 12:39:47 PM6/26/13
to google-visua...@googlegroups.com
They are brand new, so easy to miss  >;o)
Reply all
Reply to author
Forward
0 new messages