Skip to main content

Tutorial: Building a Bar Chart

In this tutorial, you’ll create a complete bar chart visualization from scratch. We’ll explain every configuration option and show you how to customize the chart.
This tutorial assumes you’ve already installed Highcharts. If not, see the Installation guide first.

What We’re Building

We’ll create a horizontal bar chart showing fruit consumption by two people. Here’s what the final result will look like:
  • Horizontal bars (not vertical columns)
  • Two data series (Jane and John)
  • Three categories (Apples, Bananas, Oranges)
  • Interactive tooltips and legend

Step-by-Step Implementation

1

Create the HTML structure

First, create an HTML file with the Highcharts library and a container for the chart:
Key points:
  • The container div needs an ID for Highcharts to reference
  • Set explicit width and height (either inline styles or CSS)
  • The exporting module adds the download menu
  • The accessibility module improves screen reader support
2

Initialize the chart

Add a script tag with the chart initialization code:
Why use DOMContentLoaded?This event ensures the page is fully loaded before trying to create the chart. Without it, the container div might not exist yet.
The Highcharts.chart() function returns a chart object that you can use to update or destroy the chart later.
3

Set the chart type

Configure the chart type as ‘bar’ (horizontal bars):
Available chart types:
  • 'bar' - Horizontal bars
  • 'column' - Vertical bars
  • 'line' - Line chart
  • 'area' - Area chart
  • 'pie' - Pie chart
  • 'scatter' - Scatter plot
  • And many more
4

Add title and subtitle

Give your chart a descriptive title:
You can customize the title further:
5

Configure the X-axis

Set up the categories for the X-axis (which appears vertically in a bar chart):
Understanding axes in bar charts:
  • In bar charts, the X-axis is vertical (shows categories)
  • The Y-axis is horizontal (shows values)
  • This is opposite from column charts
6

Configure the Y-axis

Set up the Y-axis (horizontal in bar charts) for the values:
Y-axis options explained:
  • min: 0 - Start the axis at zero
  • align: 'high' - Position title at the end of the axis
  • overflow: 'justify' - Keep labels within chart bounds
7

Add the data series

Define the data you want to visualize:
Data structure:
  • Each object in the series array is one data series
  • name appears in the legend and tooltips
  • data array values correspond to the X-axis categories
  • First value is Apples, second is Bananas, third is Oranges
You can also use object notation for more control:

Complete Code

Here’s the full implementation:

Understanding the Output

When you load this page in a browser, you’ll see:
  1. Chart Area: The main visualization with horizontal bars
  2. Legend: Color-coded labels for Jane and John (bottom of chart)
  3. Axes:
    • X-axis (vertical): Shows fruit categories
    • Y-axis (horizontal): Shows quantity values
  4. Tooltips: Hover over bars to see exact values
  5. Export Menu: Button to download chart as image or data (if exporting module loaded)

Customization Examples

Change Colors

Add Data Labels

Show values directly on the bars:

Stack the Bars

Create a stacked bar chart:

Customize Tooltips

Working with Stock Charts

For time-series data, use Highcharts.stockChart() instead:
Stock charts require the highstock.js file instead of highcharts.js, or load Stock as a module.

Example: Column Chart

Here’s a complete column chart example based on a real demo from the Highcharts repository:

Using with npm

If you installed via npm, use this approach:

Applying Themes

Customize the look of all your charts with themes:
Apply themes before creating charts using Highcharts.setOptions(). These settings will affect all subsequent charts.

Common Configuration Options

Here’s a reference for the most frequently used options:

Chart Options

Title and Subtitle

Axes

Legend

Tooltip

Updating Charts Dynamically

You can update charts after creation:

Live Examples

Explore these working examples:

Next Steps

Chart Configuration

Learn how to set and organize chart options

API Reference

Complete API documentation for all options

Chart Types

Explore all available chart types

Styling with CSS

Advanced styling with CSS and styled mode

Troubleshooting

Chart not displaying

  • Ensure the container div has explicit dimensions (width and height)
  • Check that Highcharts is loaded before your chart code runs
  • Verify the container ID matches in both HTML and JavaScript
  • Open browser console to check for JavaScript errors

Data not showing

  • Verify your data array matches the number of categories
  • Check that data values are numbers, not strings
  • Ensure the series array is properly formatted

Module not working

  • Load modules after the main Highcharts script
  • Check the correct module name and path
  • Some features require specific modules (e.g., 3D charts need highcharts-3d.js)
For more help, visit www.highcharts.com/support or search Stack Overflow with the highcharts tag.