Google Barchart, create Bar with 2 Annotations

Asked

Viewed 177 times

2

I own the following structure of a google barchart:

google.charts.load('current', {
  packages: ['corechart', 'bar']
});
google.charts.setOnLoadCallback(drawMultSeries);

function drawMultSeries() {
  var data = google.visualization.arrayToDataTable([
    ["", "", { "role": "style" }, { "role": "annotation" }, { "role": "annotation" }, { "role": "annotation" }],
    ["x", 19, "#4169C0", "19", {
      v: 0, f: ""
    }, "R$ 22.500,00"],
    ["y", 39, "#3758A5", "39", {
      v: 0, f: ""
    }, "R$ 97.500,00"],
    ["a", 60, "#273B70", "60", {
      v: 0, f: ""
    }, "R$ 150.000,00"],
    ["b", 82, "#050D20", "82", {
      v: 0, f: ""
    }, "R$ 205.000,00"]
  ]);

  var options = {
    "title": "",
    "height": "100",
    "chartArea": {
      "top": 7,
      "left": 15,
      "right": 30,
      "width": "100%"
    },
    "legend": {
      "position": "none"
    },
    "hAxis": {
      "title": "",
      "gridlines": {
        "color": "#ccc"
      },
    },
    "vAxis": {
      "title": "",
      "textPosition": "none",
      "gridlines": {
        "color": "#ccc"
      }
    },
    "bar": {
      "groupWidth": "70%"
    },
    "tooltip": {
      "trigger": "none"
    }
  };

  var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
  chart.draw(data, options);
}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

From behind I’m gathering the data, 19 | R$ 22.500,00, now arose the need to separate these Labels and include them in different barchart locations generating the following visualization:

inserir a descrição da imagem aqui

I think you should work with annotations, maybe create two different ones. I searched documentation something about it and I haven’t found any similar example.

  • Marcelo, do you say separate 19 from R$22,500, for example? How are you putting them together?

  • Exactly, for me it is easy to separate these data, I mounted there only as a test, but it could be "19", "R$ 22.500,00"

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.