Documentation Index
Fetch the complete documentation index at: https://mintlify.com/highcharts/highcharts/llms.txt
Use this file to discover all available pages before exploring further.
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
Create the HTML structure
First, create an HTML file with the Highcharts library and a container for the chart:Key points:
- The
containerdiv 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
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.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
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
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 zeroalign: 'high'- Position title at the end of the axisoverflow: 'justify'- Keep labels within chart bounds
Add the data series
Define the data you want to visualize:Data structure:
- Each object in the
seriesarray is one data series nameappears in the legend and tooltipsdataarray 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:- Chart Area: The main visualization with horizontal bars
- Legend: Color-coded labels for Jane and John (bottom of chart)
- Axes:
- X-axis (vertical): Shows fruit categories
- Y-axis (horizontal): Shows quantity values
- Tooltips: Hover over bars to see exact values
- 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, useHighcharts.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.