A bar chart for comparing categories with single, grouped, stacked, and horizontal bar layouts.
BarChartruns on the UI thread. React renders the parts once; data changes, layout, animations, scrubbing and labels update through Reanimated shared values without re-rendering. Rendering a chart requires the optionalreact-native-skiapeer (>=3.0.0).
import { BarChart } from 'heroui-native-pro';<BarChart data={...} xKey="...">
<BarChart.Grid />
<BarChart.XAxis />
<BarChart.YAxis />
<BarChart.Bar dataKey="..." />
<BarChart.Crosshair />
<BarChart.Tooltip dataKey="..." />
</BarChart>xKey and the parts. Every category gets an equal slot.stack id stand side by side in each category; bars sharing one stack in render order.LineChart.<BarChart data={SALES} xKey="month" className="h-[220px]">
<BarChart.Grid />
<BarChart.XAxis />
<BarChart.YAxis />
<BarChart.Bar dataKey="sales" />
</BarChart>By default the bars of a category fill barRatio (60%) of its slot. barSize sets a fixed thickness instead. radius rounds the value end of each bar.
<BarChart.Bar dataKey="sales" barSize={12} radius={12} />Bars without a stack id stand side by side, barGap apart, in render order.
<BarChart data={REVENUE_BY_CHANNEL} xKey="month" className="h-[220px]">
<BarChart.YAxis format={formatThousands} />
<BarChart.Bar dataKey="online" colorClassName="accent-chart-3" />
<BarChart.Bar dataKey="retail" colorClassName="accent-chart-2" />
<BarChart.Bar dataKey="direct" colorClassName="accent-chart-1" />
</BarChart>Give every layer the same stack id. The first one rendered is the bottom layer, and only the top layer gets rounded corners.
<BarChart.Bar dataKey="starter" stack="plan" colorClassName="accent-chart-1" />
<BarChart.Bar dataKey="pro" stack="plan" colorClassName="accent-chart-3" />
<BarChart.Bar dataKey="enterprise" stack="plan" colorClassName="accent-chart-4" />Different stack ids stand side by side, so grouped stacks work too.
orientation="horizontal" lists the categories down the left side, in row order from the top. The YAxis then shows the categories and the XAxis the values; the grid draws vertical lines.
<BarChart
data={TOP_PRODUCTS}
xKey="product"
orientation="horizontal"
className="h-[220px]"
>
<BarChart.Grid />
<BarChart.XAxis />
<BarChart.YAxis />
<BarChart.Bar dataKey="units" barSize={12} radius={12} />
</BarChart>colors takes gradient stops from the base of the plot to its far end (bottom to top, or left to right when horizontal). Read theme colors with useCSSVariable.
const colors = [chart1, chart3, chart5];
<BarChart.Bar dataKey="sales" colors={colors} radius={8} />;A new data array animates the bars to their new values (animate on the root). animateIn grows the bars out of the baseline on mount (down for negative values); change resetKey to replay it.
<BarChart.Bar dataKey="sales" animateIn={600} resetKey={replay} />The value axis always includes zero, and its ends are rounded out to whole ticks, so the top and bottom grid lines frame the bars. yDomain fixes either end.
<BarChart data={SALES} xKey="month" yDomain={{ max: 100 }}>Every category label is shown when they fit. Otherwise every n-th label is shown, evenly spaced, so neighbours keep at least gap pixels between them.
<BarChart data={SALES} xKey="month" className="h-[220px]">
<BarChart.Bar dataKey="sales" />
<BarChart.Crosshair />
<BarChart.Tooltip dataKey="sales" followPoint />
</BarChart>See LineChart for formatters, onSelect and custom tooltip content; they work the same way.
import { Card } from 'heroui-native';
import { BarChart } from 'heroui-native-pro';
import { View } from 'react-native';
const DATA = [
{ month: 'Jan', sales: 18 },
{ month: 'Feb', sales: 32 },
{ month: 'Mar', sales: 28 },
{ month: 'Apr', sales: 45 },
{ month: 'May', sales: 38 },
{ month: 'Jun', sales: 52 },
];
const formatWhole = (value: number) => {
'worklet';
return `${Math.round(value)}`;
};
export default function SalesChart() {
return (
<View className="flex-1 justify-center px-5">
<Card>
<Card.Header>
<Card.Title>Daily sales</Card.Title>
</Card.Header>
<Card.Body>
<BarChart data={DATA} xKey="month" className="h-[220px]">
<BarChart.Grid />
<BarChart.XAxis />
<BarChart.YAxis format={formatWhole} />
<BarChart.Bar dataKey="sales" barSize={16} radius={8} />
<BarChart.Crosshair />
<BarChart.Tooltip dataKey="sales" followPoint />
</BarChart>
</Card.Body>
</Card>
</View>
);
}Same props as LineChart, plus:
| prop | type | default | description |
|---|---|---|---|
orientation | 'vertical' | 'horizontal' | 'vertical' | horizontal lists the categories down the side and draws bars across. |
domainPadding | number | 0 | Pixels between the plot edges and the outermost values. |
| prop | type | default | description |
|---|---|---|---|
dataKey | string | - | Field of each row to plot. |
colorClassName | string | 'accent-chart-3' | Uniwind color class for the fill. |
colors | string[] | - | Gradient stops from the base of the plot to its far end; replaces color. |
opacity | number | 1 | Fill opacity. |
stack | string | - | Bars with the same id stack in render order; others stand side by side. |
radius | number | 4 | Corner radius at the value end. Only the top of a stack is rounded. |
barSize | number | - | Fixed bar thickness in pixels. |
barRatio | number | 0.6 | Share of each category's slot its bars fill together. |
barGap | number | 4 | Space between bars standing side by side. |
animateIn | boolean | number | - | Grows the series out of its baseline on mount (down for values below it); a number sets the duration in ms. |
resetKey | unknown | - | Changing it replays animateIn. |
axis | 'left' | 'right' | 'left' | Y-axis the bars are plotted against (see ComposedChart). |
Same as on LineChart.