1
votes

I'd like to do the same thing described in this question, except that I want to do it for a horizontal bar chart (the bars are horizontal instead of vertical). I'll copy the image from that question here:

enter image description here

I'd like to have a stacked horizontal bar chart similar to this with a vertical line.

It seems that ComboCharts doesn't support horizontal bar charts so I was hoping there might be another way.

1

1 Answers

1
votes

using orientation: 'vertical' will rotate the axes so that a column chart becomes a bar chart

see following working snippet...

google.charts.load('current', {
  callback: function () {
    var container = document.getElementById('chart_div');
    var chart = new google.visualization.ComboChart(container);

    var data = google.visualization.arrayToDataTable([
      ['Genre', 'Fantasy & Sci Fi', 'Romance', 'Mystery/Crime', 'General', 'Western', 'Literature', 'Minimum', 'Maximum'],
      ['2010', 10, 24, 20, 32, 18, 5, 90, 140],
      ['2020', 16, 22, 23, 30, 16, 9, 90, 140],
      ['2030', 28, 19, 29, 30, 12, 13, 90, 140]
    ]);

    var options = {
      bar: {
        groupWidth: '75%'
      },
      height: 400,
      isStacked: true,
      legend: {
        position: 'bottom'
      },
      orientation: 'vertical',
      series: {
        6: {
          color: '#000000',
          type: 'line'
        },
        7: {
          color: '#000000',
          type: 'line'
        }
      },
      seriesType: 'bars',
      width: 600,
    };

    chart.draw(data, options);
  },
  packages: ['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>