Population pyramid (negatives)
Two-sided bars around zero with absolute labels.
Open the chart without page chrome ↗
const options = {
chart: {
height: 380,
fontFamily: "Inter, Geist, \"IBM Plex Sans\", system-ui, sans-serif",
type: "bar",
stacked: true,
toolbar: {
show: false
}
},
series: [
{
name: "Men",
data: [-2.1, -2.2, -3.1, -3.9, -4.7, -5, -5.9, -6.5, -7.6]
},
{
name: "Women",
data: [2.5, 2.7, 3.6, 4.1, 4.2, 5.1, 5.5, 6.2, 7.1]
}
],
xaxis: {
categories: ["85+", "75–84", "65–74", "55–64", "45–54", "35–44", "25–34", "15–24", "0–14"],
labels: {
formatter: (v) => Math.abs(Math.round(v)) + '%'
}
},
yaxis: {
min: -8,
max: 8
},
tooltip: {
y: {
formatter: (v) => Math.abs(v) + '%'
}
},
plotOptions: {
bar: {
horizontal: true,
barHeight: "82%"
}
},
dataLabels: {
enabled: false
},
grid: {
xaxis: {
lines: {
show: false
}
}
},
title: {
text: "Population by age (share)"
},
theme: {
mode: "light",
preset: "coastal"
}
}
const chart = new WestCoastCharts(document.querySelector('#chart'), options)
chart.render()import WestCoastCharts from 'west-coast-charts'
const options = {
chart: {
height: 380,
fontFamily: "Inter, Geist, \"IBM Plex Sans\", system-ui, sans-serif",
type: "bar",
stacked: true,
toolbar: {
show: false
}
},
series: [
{
name: "Men",
data: [-2.1, -2.2, -3.1, -3.9, -4.7, -5, -5.9, -6.5, -7.6]
},
{
name: "Women",
data: [2.5, 2.7, 3.6, 4.1, 4.2, 5.1, 5.5, 6.2, 7.1]
}
],
xaxis: {
categories: ["85+", "75–84", "65–74", "55–64", "45–54", "35–44", "25–34", "15–24", "0–14"],
labels: {
formatter: (v) => Math.abs(Math.round(v)) + '%'
}
},
yaxis: {
min: -8,
max: 8
},
tooltip: {
y: {
formatter: (v) => Math.abs(v) + '%'
}
},
plotOptions: {
bar: {
horizontal: true,
barHeight: "82%"
}
},
dataLabels: {
enabled: false
},
grid: {
xaxis: {
lines: {
show: false
}
}
},
title: {
text: "Population by age (share)"
},
theme: {
mode: "light",
preset: "coastal"
}
}
const chart = new WestCoastCharts(document.querySelector('#chart'), options)
await chart.render() Waiting for the chart.
Open Data & agent view to read this chart through chart.describe().
Read from the running library through its optional agent/describe module. Text, table and JSON share the same snapshot. Demo data only.
$ wcc chart export bar-bar-with-negative.json --out bar-bar-with-negative.svg --with-table Public agent tools 0.2.3, tested with Library 1.1.5; available from the versioned GitHub release and npm. Save a JSON spec first and check the loaded runtime and supported modules before rendering. Command reference
Loading /gallery/bar/bar-with-negative/index.md …