Highcharts Tutorial
Chart Types
A reverse bar chart, also known as a horizontal bar chart, is a chart type that displays data in horizontal bars rather than vertical bars. Highcharts supports horizontal bar charts with the chart.type
option set to 'bar'
and the xAxis
and yAxis
options reversed.
To create a reverse bar 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: 'bar' }, title: { text: 'Reverse Bar Chart' }, xAxis: { reversed: true, categories: ['Category 1', 'Category 2', 'Category 3', 'Category 4', 'Category 5'] }, yAxis: { title: { text: 'Y Axis Label' } }, series: [{ name: 'Series Name', data: [10, 20, 30, 40, 50] }] });
In this example, we're creating a reverse bar chart with the Highcharts chart
function and passing in a set of options:
chart.type
is set to 'bar'
to create a bar charttitle.text
is set to 'Reverse Bar Chart'
to set the main titlexAxis.reversed
is set to true
to reverse the direction of the horizontal barsxAxis.categories
is set to an array of category labels for the y-axis (which is displayed horizontally in a reverse bar chart)yAxis.title
is used to set the label for the x-axisseries
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 horizontal bars.With these options, you can create a reverse bar chart with customizable data and appearance. Note that Highcharts supports other options to customize the appearance of bar charts, including the color
, stacking
, and pointWidth
options.
Customizing appearance in Highcharts Reverse Bar Chart: To customize the appearance of a Reverse Bar Chart in Highcharts, you can use various options like colors, bar width, and more. Here's an example code snippet:
Highcharts.chart('container', { chart: { type: 'bar' }, plotOptions: { bar: { dataLabels: { enabled: true } } }, xAxis: { reversed: true // Reverse the order of the x-axis }, series: [{ name: 'Reverse Bar Data', data: [10, 20, 30, 40, 50] }] });
Adding data to Highcharts Reverse Bar Chart:
Adding data to a Reverse Bar Chart is similar to other bar charts. Use the data
property within the series
object. Here's an example:
series: [{ name: 'Reverse Bar Data', data: [10, 20, 30, 40, 50] }]
Stacked Reverse Bar Chart in Highcharts:
To create a stacked Reverse Bar Chart, you can set the stacking
property in the plot options. Here's an example:
plotOptions: { bar: { stacking: 'normal' } }, series: [{ name: 'Category 1', data: [10, 20, 30, 40, 50] }, { name: 'Category 2', data: [5, 10, 15, 20, 25] }]
Grouped Reverse Bar Chart using Highcharts:
To create a grouped Reverse Bar Chart, omit the stacking
property. Here's an example:
plotOptions: { bar: { // No stacking property for grouped chart } }, series: [{ name: 'Category 1', data: [10, 20, 30, 40, 50] }, { name: 'Category 2', data: [5, 10, 15, 20, 25] }]
Interactive features in Highcharts Reverse Bar Chart: Highcharts supports interactive features like tooltips, click events, and legends in Reverse Bar Charts. You can enable these features to enhance user interaction. Here's a snippet for tooltip configuration:
tooltip: { pointFormat: 'Value: {point.y}' }