Highcharts Tutorial
Chart Types
A stacked column chart is a chart type that displays data as a series of columns stacked on top of each other, with each column representing a category or data series and the height of the column representing the value of that category or series. Highcharts supports stacked column charts with the chart.type
option set to 'column'
and the plotOptions.column.stacking
option enabled.
To create a stacked column chart using Highcharts, you can follow these steps:
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="chart-container"></div>
Highcharts.chart('chart-container', { chart: { type: 'column' }, title: { text: 'Stacked Column Chart' }, xAxis: { categories: ['Category 1', 'Category 2', 'Category 3', 'Category 4', 'Category 5'] }, yAxis: { title: { text: 'Y Axis Label' } }, plotOptions: { column: { stacking: 'normal' } }, series: [{ name: 'Series 1', data: [10, 20, 30, 40, 50] }, { name: 'Series 2', data: [20, 30, 40, 50, 60] }, { name: 'Series 3', data: [30, 40, 50, 60, 70] }] });
In this example, we're creating a stacked column chart with the Highcharts chart
function and passing in a set of options:
chart.type
is set to 'column'
to create a column charttitle.text
is set to 'Stacked Column Chart'
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-axisplotOptions.column.stacking
is set to 'normal'
to enable stacking of columnsseries
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 values for each category, which are displayed as stacked columns. The columns are stacked on top of each other to show the contribution of each data series to the overall value.With these options, you can create a stacked column chart with customizable data and appearance. Note that Highcharts supports other options to customize the appearance of column charts, including the color
, marker
, and tooltip
options.
Customizing appearance in Highcharts Stacked Column Chart:
Highcharts.chart('container', { chart: { type: 'column' }, plotOptions: { column: { color: '#FFA07A', // Set column color borderColor: 'black', // Set border color borderWidth: 2 // Set border width } }, // Other configuration options... });
Adding data to Highcharts Stacked Column Chart:
series
array.Highcharts.chart('container', { series: [{ name: 'Series 1', data: [5, 3, 4, 7, 2] }, { name: 'Series 2', data: [2, 4, 1, 3, 5] }], // Other configuration options... });
Grouped Stacked Column Chart in Highcharts:
stacking
option and providing categories for grouping.Highcharts.chart('container', { chart: { type: 'column' }, plotOptions: { column: { stacking: 'normal' // 'normal' for grouped stacking } }, // Other configuration options... });
Interactive features in Highcharts Stacked Column Chart:
Highcharts.chart('container', { tooltip: { formatter: function () { return 'Point value: ' + this.y; } }, // Other configuration options... });
Handling multiple series in Highcharts Stacked Column Chart:
series
array.Highcharts.chart('container', { series: [{ name: 'Series 1', data: [1, 2, 3] }, { name: 'Series 2', data: [4, 5, 6] }], // Other configuration options... });