isStacked not working

843 views
Skip to first unread message

Nick Robinson

unread,
Aug 31, 2015, 9:16:52 PM8/31/15
to Google Visualization API
Hi there,

This might seem like a silly question but I'm trying to create a simple stacked bar chart (exactly the same as the one on the google charts "stacked bar charts" example), however, the option isStacked: true doesn't seem to do anything:

<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1.1", {packages:["bar"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
var data = google.visualization.arrayToDataTable([
  ['Genre', 'Fantasy & Sci Fi', 'Romance', 'Mystery/Crime', 'General',
  'Western', 'Literature', { role: 'annotation' } ],
  ['2010', 10, 24, 20, 32, 18, 5, ''],
  ['2020', 16, 22, 23, 30, 16, 9, ''],
  ['2030', 28, 19, 29, 30, 12, 13, '']
]);

      var options = {
        width: 600,
        height: 400,
        legend: { position: 'top', maxLines: 3 },
        bar: { groupWidth: '75%' },
        isStacked: true
      };

      var chart = new google.charts.Bar(document.getElementById('barchart_stacked'));

      chart.draw(data, options);
    }
    </script>
  </head>
  <body>
    <div id="barchart_stacked" style="width: 900px; height: 500px;"></div>
  </body>
</html>

Thanks in advance for any assistance

Sergey Grabkovsky

unread,
Sep 1, 2015, 9:38:12 AM9/1/15
to Google Visualization API
Hi Nick,

The isStacked option is a classic chart option, and doesn't work directly for Material charts. You'll have to call google.charts.Bar.convertOptions(options) in order to convert the classic options to Material. Here's the relevant excerpt from our documentation:

The Material Charts are in beta. The appearance and interactivity are largely final, but the way options are declared is not. If you are converting a Classic Bar Chart to a Material Bar Chart, you'll want to replace this line: 

chart.draw(data, options);
...with this: 
chart.draw(data, google.charts.Bar.convertOptions(options));

--
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 http://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/7197aa56-7f66-4667-9f8b-c44e1897be00%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages