BarChart
Plot each data item as a bar, suitable for comparing categorical values. It can be arranged horizontally or vertically, set numerical ranges, category labels and numerical labels, and supports positive and negative values.
Example
function main() {
return (
<BarChart
data={[
{ value: 30, label: 'A' },
{ value: 70, label: 'B' },
]}
axis="vertical"
rangeY={[0, 100]}
showLabels={true}
showValueLabels={true}
background={$env.accent}
cornerRadius={6}
yAxis={{ stroke: $env.foreground, lineWidth: 1 }}
/>
);
}
Usage
- Each data item is one bar, ordered by the array; no x value is needed. axis=horizontal rotates the bar direction, but the value range is still rangeY. Automatic ranges include zero, negatives extend across the baseline, and background fills bars.
- rangeX/rangeY bound numeric values, not labels. Hiding labels does not hide axis lines; use stroke="clear" in xAxis/yAxis to hide them separately. Native layout selects non-overlapping labels, so enabling labels does not guarantee every label appears.
- contentAnimation transitions text, images or structured data rather than scalar properties. interpolate needs compatible structure: matching Polyline point count/closed state, Path command sequence or chart samples. Structural changes update immediately.
Properties
dataReadonlyArray<BarChartDataPoint>Categories in array order. Each item has a numeric value and an optional label.
[{value: 10, label: "A"}, {value: 20, label: "B"}, {value: 30, label: "C"}]axis?"horizontal" | "vertical"Bar direction: vertical runs left to right; horizontal runs top to bottom.
"vertical"rangeY?ChartRangeVisible value range [min, max]. Omit to fit data and include zero.
[0, 100]showLabels?booleanShow category labels. Missing labels stay empty; native layout prevents overlap.
trueshowValueLabels?booleanShow automatically generated numeric axis labels.
truebarThickness?number | "auto"Bar thickness in points, or auto to fit category spacing.
"auto"xAxis?ChartAxisStyleHorizontal axis line at the bottom of the plot. Defaults to foreground with 1pt width; use clear stroke to hide.
{stroke: HDR($env.foreground), lineWidth: 1}yAxis?ChartAxisStyleVertical axis line at the left of the plot. Defaults to foreground with 1pt width; use clear stroke to hide.
{stroke: HDR($env.foreground), lineWidth: 1}background?PaintFill paint for each bar. Defaults to the theme foreground.
HDR($env.dark ? "white" : "black")cornerRadius?numberCorner radius of each bar, clamped to its size.
0stroke?PaintStroke paint; accepts a color or gradient. Use clear to hide the stroke.
"clear"lineWidth?numberStroke thickness in points; 0 draws no stroke.
2strokePosition?"inside" | "center" | "outside"Stroke placement relative to each bar. Defaults to inside.
"inside"dash?number[]Alternating painted and empty lengths in points; an empty array makes a solid stroke.
[]dashPhase?numberOffset along the dash pattern, in points.
0contentAnimation?ContentAnimationOptional content transition. Interpolate requires the same category count and axis; otherwise updates immediately.
{type: "interpolate", duration: 0.25}Common properties
width?number | "auto" | "fill"Width in points, auto sizing or parent fill.
"fill"height?number | "auto" | "fill"Height in points, auto sizing or parent fill.
"fill"x?numberVisual offset in points: x moves right, y moves down. Does not change layout space.
0y?numberVisual offset in points: x moves right, y moves down. Does not change layout space.
0transform?ViewTransformTransform the whole View without changing layout. Translation uses points; rotation/skew use degrees; scale 1 is unchanged; anchors use 0–1.
{rotation: 0}opacity?numberOpacity of the whole View: 0 is transparent, 1 is opaque.
1clipped?booleanClip drawing that extends beyond the View bounds.
falseclip?"rectangle" | "ellipse"Clipping shape: rectangle or ellipse. Material also accepts false to disable clipping.
"rectangle"mask?View | nullAlpha mask View. Centered without affecting layout; null disables masking.
<Circle width="fill" height="fill" background="white"/>zIndex?numberDrawing order among siblings; larger values appear in front.
0blur?numberBlur radius in points; 0 disables blur.
4innerShadow?DrawingEffectEffect color, opacity, blur radius and x/y offset. Distances are in points.
{color: HDR("black"), opacity: 0.5, radius: 4, x: 0, y: 2}glow?DrawingEffectEffect color, opacity, blur radius and x/y offset. Distances are in points.
{color: HDR("cyan"), radius: 8, opacity: 0.8}shadowColor?ColorColor of the outer shadow.
HDR("black")shadowOpacity?numberOuter shadow opacity from 0 to 1; 0 hides it.
0shadowRadius?numberOuter shadow blur radius in points.
4shadowX?numberOuter shadow offset in points: x right, y down.
0shadowY?numberOuter shadow offset in points: x right, y down.
2animations?BarChartAnimation[]Animate a supported property when it changes. duration/delay use seconds; from/to set endpoints; repeat and autoreverse control repetition; wrap sets a periodic range.
[{property: "opacity", duration: 0.25, curve: "easeInOut"}]key?string | numberStable identity among siblings.
Practical example
function main() {
return (
<BarChart
width={260}
height={160}
axis="horizontal"
rangeY={[-50, 100]}
data={[
{ value: 80, label: 'A' },
{ value: -25, label: 'B' },
{ value: 45, label: 'C' },
]}
showLabels={true}
showValueLabels={true}
background={$env.accent}
cornerRadius={4}
xAxis={{ stroke: $env.foreground, dash: [4, 3] }}
yAxis={{ stroke: 'clear' }}
/>
);
}
Animation
widthheightxyopacitybackgroundcornerRadiusblurshadowColorshadowOpacityshadowRadiusshadowXshadowYbarThicknessstrokelineWidthdashPhasetransform.translateXtransform.translateYtransform.scaleXtransform.scaleYtransform.rotationtransform.skewXtransform.skewYtransform.anchorXtransform.anchorYrangeY.0rangeY.1xAxis.lineWidthxAxis.dashPhaseyAxis.lineWidthyAxis.dashPhasexAxis.strokeyAxis.strokeWhen omitted
The table lists omission behavior verified against implementation. Property examples are copyable syntax, not defaults. Pass explicit values for a fixed result; contextual dimensions and theme colors are not fixed constants.
| Properties | When omitted |
|---|---|
data | [] |
axis | "vertical" |
showLabels | true |
showValueLabels | true |
cornerRadius | 0 |
strokePosition | "inside" |
background | HDR($env.dark ? 'white' : 'black') |
xAxis | { stroke: HDR($env.foreground), lineWidth: 1 } |
yAxis | { stroke: HDR($env.foreground), lineWidth: 1 } |