Skip to content

BarChart

The <BarChart> primitive draws a vertical bar chart from an array of labeled values. Use it for statistics, comparisons, and any data-driven visualization.

1%Paris0%Lyon0%the0%Berlin0%London
0.00s / 1.97s · F0
PropTypeDefaultDescription
bars{ label: string, value: number, color?: string }[]Array of bar definitions
xnumber0X position of the chart
ynumber0Y position of the chart
widthnumber400Total chart width in pixels
heightnumber250Total chart height in pixels
barColorstring'#4f46e5'Default fill color for bars
labelColorstring'currentColor'Color of bar labels
showValuesbooleantrueDisplay the value above each bar
valueFormat'number' | 'percent''number'Format values as plain numbers or percentages
maxValuenumberundefinedOverride the automatic y-axis maximum
gapnumber0.2Gap between bars as a fraction of bar width (0–1)
labelFontSizenumber12Font size for labels
elements: {
cities: {
id: 'cities',
type: 'barChart',
props: {
type: 'barChart',
bars: [
{ label: 'Paris', value: 0.92, color: '#6c5ce7' },
{ label: 'Lyon', value: 0.03, color: '#a29bfe' },
{ label: 'Berlin', value: 0.015, color: '#81ecec' },
],
x: 50, y: 30, width: 400, height: 230,
labelColor: '$foreground', showValues: true, valueFormat: 'percent', maxValue: 1,
},
},
}