Summing up the summary table

I have two unsigned integers in the string: X and Y.
X is always less than Y because it is a subset of it.

I want to combine these two values ​​in one line. However, the Stacking Bar Chart adds values ​​instead of “overlapping” them.

This is what isStacked: trueleads to:
XXXYYYYY (3x + 5y, axis reaches 8)

And here is my goal:
XXXYY (3x within 5y, axis reaches 5)

How can I “merge” values ​​into one bar, which is based only on Y, and thus does not affect the maximum value of the axis?

+4
source share
1 answer

the data will need to be adjusted, the chart settings will not be received.

, Y...

google.charts.load('current', {
  packages: ['corechart'],
  callback: drawChart
});

function drawChart() {
  var data = google.visualization.arrayToDataTable([
    ['Year', 'X', 'Y'],
    ['2016', 3, 5]
  ]);

  var view = new google.visualization.DataView(data);
  view.setColumns([0, 1, {
    calc: function (data, row) {
      return {
        v: data.getValue(row, 2) - data.getValue(row, 1),
        f: data.getValue(row, 2).toString()
      };
    },
    type: 'number',
    label: 'Y'
  }]);

  var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
  chart.draw(view, {isStacked: true});
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
Hide result
+1

Source: https://habr.com/ru/post/1629383/


All Articles