Adding specific total values to stacked bar chart

Hi Guys,

Wondering if it’s possible to include the total value of two categories of my stacked bar graph, at the right edge of the chart? I’d like to add together the “strongly agree” and “somewhat agree” from the legend.

I’ve started working on the chart here:
Working Chart

If that link doesn’t work, below is what I mean – with the totals of the two percents added on the right.

Let me know if there is a way I can do that. Thank you!

Samantha :slight_smile:

Hi Samantha,

Thanks for reaching out. I can’t see the chart from your given link. But yesterday you shared the chart in support, and i have provided a solution there, i am giving the same solution here as well.

If you’d like to create a sample chart like this: https://api.everviz.com/share/3j4Hc9QxO, you can follow the steps below:

  1. Fix the cutoff issue:
  • In your chart, update the Horizontal axis type from Linear to Category via:
    Customize -> Axes -> Horizontal axis -> Type
  1. Create the “Total Agree” column:
  • Go to Customize -> Advanced -> Plot Options -> Series and add normal instead of percent .
  • Then, add the following code in the Custom Code section:
Highcharts.merge(true, options, {  yAxis: [{
    stackLabels: {
      enabled: true,
      align: 'right',
      verticalAlign: 'middle',
      x: 20,
      style: {
        fontSize: '13px',
        fontWeight: 'bold',
        color: '#000'
      },
      formatter: function () {
        const chart = this.axis.chart;
        const pointIndex = this.x; 
        const series = chart.series;

        // Sum only the first two columns (Strongly agree + Somewhat agree)
        let totalAgree = 0;
        [0, 1].forEach(i => {
          if (series[i] && series[i].visible && series[i].yData[pointIndex] !== undefined) {
            totalAgree += series[i].yData[pointIndex];
          }
        });

        return totalAgree ? totalAgree + '%' : '';
      }
    }
  }]
});

This should resolve the issue.
Please let me know if you have any other query.

Thank you for your patience!

Best regards,
Faria