Highcharts Tutorial
Chart Types
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 charttitle.text
is set to 'Stacked Column Chart Using Percentages'
to set the main titlexAxis.categories
is set to an array of category labels for the x-axisyAxis.title
is used to set the label for the y-axisyAxis.labels.format
is set to '{value}%'
to format the y-axis labels as percentagesyAxis.stackLabels.enabled
is set to true
to enable stack labelsyAxis.stackLabels.format
is set to '{total}%'
to format the stack labels as percentagestooltip.valueSuffix
is set to '%'
to display the values in the chart as percentagesplotOptions.column.stacking
is set to 'percent'
to stack the columns as percentagesseries
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.
Customizing appearance in Highcharts Stacked Column Chart with percentages:
Highcharts.chart('container', { plotOptions: { column: { dataLabels: { format: '{point.percentage:.1f}%' } } }, // Other configuration options... });
Adding data to Highcharts Stacked Column Chart with percentages:
Highcharts.chart('container', { series: [{ name: 'Series 1', data: [10, 30, 25, 45], stack: 'percent' }], // Other configuration options... });
Grouped Stacked Column Chart with percentages in Highcharts:
Highcharts.chart('container', { plotOptions: { column: { stacking: 'percent' } }, // Other configuration options... });
Interactive features in Highcharts Stacked Column Chart with percentages:
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... });
Handling percentage values in Highcharts Stacked Column Chart:
Highcharts.chart('container', { series: [{ name: 'Series 1', data: [10, 30, 25, 45], stack: 'percent' }], // Other configuration options... });