Highcharts Stacked Column Chart Using Percentages

To create a stacked column chart using percentages in Highcharts, you can calculate the percentage of each data point in the data series and set the tooltip.valueSuffix option to '%'. This will display the values in the chart as percentages.

Here's an example of how to create a stacked column chart using percentages:

// Sample data
const data = [
  ['Category 1', 10, 20, 30],
  ['Category 2', 20, 30, 40],
  ['Category 3', 30, 40, 50],
  ['Category 4', 40, 50, 60],
  ['Category 5', 50, 60, 70]
];

// Calculate the percentages
const total = data.reduce((sum, row) => sum + row.slice(1).reduce((rowSum, value) => rowSum + value, 0), 0);
const percentData = data.map(row => [row[0], ...row.slice(1).map(value => Math.round(value / total * 100))]);

// Create the chart
Highcharts.chart('container', {
  chart: {
    type: 'column'
  },
  title: {
    text: 'Stacked Column Chart Using Percentages'
  },
  xAxis: {
    categories: percentData.map(row => row[0])
  },
  yAxis: {
    title: {
      text: 'Percentage'
    },
    labels: {
      format: '{value}%'
    },
    stackLabels: {
      enabled: true,
      format: '{total}%'
    }
  },
  tooltip: {
    valueSuffix: '%'
  },
  plotOptions: {
    column: {
      stacking: 'percent'
    }
  },
  series: [
    {
      name: 'Series 1',
      data: percentData.map(row => row[1])
    },
    {
      name: 'Series 2',
      data: percentData.map(row => row[2])
    },
    {
      name: 'Series 3',
      data: percentData.map(row => row[3])
    }
  ]
});

In this example, we first calculate the percentages of each data point in the data series by dividing each value by the total value and multiplying by 100. We then create the chart with the following options:

  • chart.type is set to 'column' to create a column chart
  • title.text is set to 'Stacked Column Chart Using Percentages' to set the main title
  • xAxis.categories is set to an array of category labels for the x-axis
  • yAxis.title is used to set the label for the y-axis
  • yAxis.labels.format is set to '{value}%' to format the y-axis labels as percentages
  • yAxis.stackLabels.enabled is set to true to enable stack labels
  • yAxis.stackLabels.format is set to '{total}%' to format the stack labels as percentages
  • tooltip.valueSuffix is set to '%' to display the values in the chart as percentages
  • plotOptions.column.stacking is set to 'percent' to stack the columns as percentages
  • series is set to an array of objects with a name and data property to define the series data. The data property contains an array of percentage values for each category, which are displayed as stacked columns.

With these options, you can create a stacked column chart with percentages in Highcharts.

  1. Customizing appearance in Highcharts Stacked Column Chart with percentages:

    • Customize appearance as usual, but consider configuring the tooltip to display percentages.
    Highcharts.chart('container', {
        plotOptions: {
            column: {
                dataLabels: {
                    format: '{point.percentage:.1f}%'
                }
            }
        },
        // Other configuration options...
    });
    
  2. Adding data to Highcharts Stacked Column Chart with percentages:

    • Add data with percentage values.
    Highcharts.chart('container', {
        series: [{
            name: 'Series 1',
            data: [10, 30, 25, 45],
            stack: 'percent'
        }],
        // Other configuration options...
    });
    
  3. Grouped Stacked Column Chart with percentages in Highcharts:

    • Grouped stacking with percentages can be achieved similarly to regular stacked charts.
    Highcharts.chart('container', {
        plotOptions: {
            column: {
                stacking: 'percent'
            }
        },
        // Other configuration options...
    });
    
  4. Interactive features in Highcharts Stacked Column Chart with percentages:

    • Maintain interactive features such as tooltips with percentage information.
    Highcharts.chart('container', {
        tooltip: {
            pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.percentage:.1f}%</b><br/>',
            // Other tooltip options...
        },
        // Other configuration options...
    });
    
  5. Handling percentage values in Highcharts Stacked Column Chart:

    • Handle percentage values as part of your data and utilize the stacking options.
    Highcharts.chart('container', {
        series: [{
            name: 'Series 1',
            data: [10, 30, 25, 45],
            stack: 'percent'
        }],
        // Other configuration options...
    });