1
votes

The following code makes a horizontal stacked barchart that looks like this:

enter image description here

If I change the height attribute to 50 and the groupWidth to 40%, the legend disappears and the chart looks like this:enter image description here

Question 1: How can I set the height of the bar and still show the legend?
Question 2: How can I get the horizontal and vertical axis to disappear?

What I am really trying to accomplish is a picture like this:

enter image description here

  <html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          [' ', 'Sales', 'Expenses'],
          [0 ,  1000,      400],
        ]);

        var options = {
          isStacked: true,
          width:    200,
          height: 60,
          vAxis: {gridlines: {count: 0}},                    
          hAxis: {gridlines: {count: 0}},          
          bar: {groupWidth: "90%"},
          legend: {position: 'top'}

        };

        var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="chart_div" ></div>
  </body>
</html>
1

1 Answers

1
votes

Set the chartArea.top option to move the chart area down and give the legend room to draw:

chartArea: {
    top: 15
}

jsfiddle