## Highcharts Bar Charts
In Highcharts, a **Bar Chart** is a variation of a column chart where the axes are flipped: the x-axis is displayed vertically on the left, and the y-axis is displayed horizontally at the bottom. This layout is highly effective for comparing data across categories, especially when category names are long or when you have a large number of data points.
This tutorial covers the core concepts, configuration options, and practical implementations of different types of Highcharts bar charts.
---
## Types of Bar Charts
Highcharts supports several variations of bar charts to suit different data visualization needs:
| No. | Chart Type | Description |
| :--- | :--- | :--- |
| 1 | **Basic Bar Chart** | Compares individual values across different categories using horizontal bars. |
| 2 | **Stacked Bar Chart** | Shows the relationship of individual items to the whole by stacking bars on top of each other. |
| 3 | **Bar Chart with Negative Values** | Displays both positive and negative values, useful for comparing divergent datasets (e.g., population pyramids). |
---
## Core Configuration & Syntax
To create a bar chart in Highcharts, you must set the `chart.type` property to `'bar'`.
```javascript
Highcharts.chart('container', {
chart: {
type: 'bar' // Specifies that this is a bar chart
},
title: {
text: 'Chart Title'
},
xAxis: {
categories: ['Category A', 'Category B', 'Category C']
},
yAxis: {
title: {
text: 'Value Unit'
}
},
series: [{
name: 'Series 1',
data: [5, 10, 15]
}]
});
```
---
## Code Examples
### 1. Basic Bar Chart
The basic bar chart is ideal for comparing discrete categories. The horizontal orientation provides ample space for long category labels on the y-axis (which acts as the visual vertical axis).
```javascript
Highcharts.chart('container', {
chart: {
type: 'bar'
},
title: {
text: 'Historic World Population by Region'
},
subtitle: {
text: 'Source: Wikipedia.org'
},
xAxis: {
categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Population (millions)',
align: 'high'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
valueSuffix: ' millions'
},
plotOptions: {
bar: {
dataLabels: {
enabled: true // Displays values directly on the bars
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 80,
floating: true,
borderWidth: 1,
backgroundColor: Highcharts.defaultOptions.legend.backgroundColor || '#FFFFFF',
shadow: true
},
credits: {
enabled: false
},
series: [{
name: 'Year 1800',
data: [107, 31, 635, 203, 2]
}, {
name: 'Year 1900',
data: [133, 156, 947, 408, 6]
}, {
name: 'Year 2012',
data: [1052, 954, 4250, 740, 38]
}]
});
```
---
### 2. Stacked Bar Chart
Stacked bar charts allow you to break down the total value of a category into its contributing parts. You can configure stacking using the `plotOptions.series.stacking` property, setting it to either `'normal'` (absolute values) or `'percent'` (percentage distribution).
```javascript
Highcharts.chart('container', {
chart: {
type: 'bar'
},
title: {
text: 'Stacked Bar Chart Example'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0,
title: {
text: 'Total Fruit Consumption'
}
},
legend: {
reversed: true // Matches the visual stacking order of the bars
},
plotOptions: {
series: {
stacking: 'normal' // Use 'percent' for percentage stacked bar charts
}
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2]
}, {
name: 'Jane',
data: [2, 2, 3, 2, 1]
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5]
}]
});
```
---
### 3. Bar Chart with Negative Values (Diverging Bar Chart)
This variation is commonly used for population pyramids or comparing two opposing datasets (e.g., Male vs. Female, Income vs. Expense).
```javascript
Highcharts.chart('container', {
chart: {
type: 'bar'
},
title: {
text: 'Population Pyramid'
},
xAxis: [{
categories: ['0-19', '20-39', '40-59', '60+'],
reversed: false,
labels: {
step: 1
}
}],
yAxis: {
title: {
text: null
},
labels: {
formatter: function () {
return Math.abs(this.value) + '%'; // Displays negative values as positive percentages
}
}
},
plotOptions: {
series: {
stacking: 'normal'
}
},
tooltip: {
formatter: function () {
return '' + this.series.name + ', age ' + this.point.category + '
' +
'Population: ' + Highcharts.numberFormat(Math.abs(this.point.y), 0) + '%';
}
},
series: [{
name: 'Male',
data: [-2.2, -2.1, -1.5, -0.8] // Negative values extend to the left
}, {
name: 'Female',
data: [2.1, 2.0, 1.6, 0.9] // Positive values extend to the right
}]
});
```
---
## Key Considerations & Best Practices
1. **Label Readability**: If your category names are long, use a bar chart instead of a column chart. The horizontal layout prevents labels from overlapping or requiring rotation.
2. **Legend Order**: When using stacked bar charts, set `legend.reversed: true` so that the order of items in the legend matches the visual stacking order of the bars.
3. **Data Labels**: For basic bar charts with few categories, enabling `dataLabels` directly on the bars can make the chart easier to read without gridlines.
4. **Color Contrast**: Ensure that stacked series have distinct, high-contrast colors so users can easily differentiate between the segments.
π Categories
- β‘ JavaScript (1589)
- π PHP (872)
- π Python3 (810)
- π HTML (691)
- βοΈ C# (650)
- π Python (594)
- β Java (552)
- βοΈ PyTorch (534)
- π§ Linux (472)
- βοΈ C (432)
- π¦ jQuery (406)
- π¨ CSS (377)
- π XML (259)
- π¦ jQuery UI (231)
- π― Bootstrap (220)
- βοΈ C++ (215)
- π °οΈ Angular (205)
- π HTML DOM (201)
- π΄ Redis (188)
- π Web Building (142)
- π Vue.js (141)
- π R (131)
- πΌ Pandas (124)
- ποΈ SQL (105)
- βοΈ Docker (86)
- βοΈ TypeScript (73)
- βοΈ Highcharts (70)
- π AI Agent (70)
- βοΈ React (68)
- π Node.js (65)
- βοΈ Machine Learning (60)
- π Git (59)
- π΅ Go (58)
- π Markdown (58)
- π’ NumPy (55)
- π§ͺ Flask (54)
- βοΈ Scala (53)
- ποΈ SQLite (52)
- π JSTL (52)
- βοΈ VS Code (51)
- π MongoDB (49)
- π Perl (48)
- π Ruby (47)
- π Matplotlib (47)
- βοΈ Uncategorized (46)
- π Swift (46)
- ποΈ PostgreSQL (46)
- βοΈ Data Structures (46)
- π Playwright (46)
- π iOS (45)
- ποΈ MySQL (44)
- βοΈ LangChain (43)
- π FastAPI (40)
- βοΈ Ionic (38)
- π Design Patterns (37)
- βοΈ Eclipse (37)
- π¨ CSS3 (34)
- π Lua (34)
- βοΈ Codex (34)
- πΈ Django (32)
- βοΈ OpenCV (32)
- π Rust (31)
- π JSP (31)
- βοΈ Claude Code (31)
- π Pillow (30)
- βοΈ OpenCode (28)
- π AI Skills (27)
- π Flutter (26)
- π Maven (26)
- π¨ Tailwind CSS (25)
- π§ TensorFlow (25)
- π Servlet (24)
- π Dart (23)
- π Assembly (23)
- βοΈ Memcached (22)
- βοΈ SVG (22)
- βοΈ Electron (22)
- π NLP (22)
- π Regex (21)
- π Android (20)
- π£ Kotlin (19)
- π Julia (19)
- π SOAP (17)
- π Selenium (17)
- π PowerShell (17)
- π Sass (16)
- π HTTP (16)
- π Zig (15)
- π AI (15)
- π AJAX (14)
- π Swagger (14)
- βοΈ Scikit-learn (13)
- βοΈ ECharts (13)
- βοΈ Chart.js (13)
- βοΈ Cursor (13)
- βοΈ SciPy (12)
- π RDF (12)
- π Ollama (12)
- π Next.js (12)
- π Plotly Dash (12)
- π JSON (11)
- π RESTful API (11)
- π WSDL (9)
- βοΈ CMake (8)
- π Firebug (7)
- π Nginx (6)
- βΈοΈ Kubernetes (6)
- π Jupyter (6)
- π LaTeX (4)
- π UniApp (4)
- ποΈ SQL Server (1)
YouTip