HorizontalBar (Component)
The HorizontalBar component draws a single-series horizontal bar chart inside a CartesianChart with orientation="horizontal".
Horizontal bar charts keep the usual Victory Native data shape: xKey identifies the category field, and yKeys identify numeric value fields. In horizontal mode, categories render on the vertical axis and values render on the horizontal axis.
Example
For a step-by-step walkthrough, see the horizontal bar chart guide.
import { CartesianChart, HorizontalBar } from "victory-native";
const DATA = [
{ category: "Audio", revenue: 42 },
{ category: "Books", revenue: -8 },
{ category: "Events", revenue: 96 },
];
export function MyChart() {
return (
<CartesianChart
orientation="horizontal"
data={DATA}
xKey="category"
yKeys={["revenue"]}
domain={{ x: [-20, 120] }}
domainPadding={{ top: 24, bottom: 24, right: 24 }}
xAxis={{ tickCount: 5 }}
yAxis={[{ yKeys: ["revenue"] }]}
>
{({ points, chartBounds }) => (
<HorizontalBar
points={points.revenue}
chartBounds={chartBounds}
color="teal"
roundedCorners={{ topRight: 8, bottomRight: 8 }}
/>
)}
</CartesianChart>
);
}
Props
HorizontalBar mirrors the Bar component API:
points: aPointsArrayfrom theCartesianChartrender function.chartBounds: thechartBoundsrender argument fromCartesianChart.innerPadding: controls the vertical space between bars whenbarWidthis not set.animate: path animation config.roundedCorners: corner radii for each bar.barWidth: fixed visual bar thickness.barCount: computes thickness as if there were a fixed number of bars.labels: value labels using the same{ position, font, color, formatLabel, rotate }shape asBar.
Horizontal Mode Notes
domain.x,viewport.x, anddomainPadding.left/rightapply to the numeric value axis.domainPadding.top/bottomapply to category spacing.- The zero baseline is used for positive and negative values.
points[key].xis the value endpoint on screen.points[key].yis the category center on screen.points[key].xValueremains the raw category value.points[key].yValueremains the raw numeric value.HorizontalBaris only supported insideCartesianChart orientation="horizontal".
When using chartPressState, the press values keep their data-semantic names:
state.x.value.valueis the raw category fromxKey.state.x.position.valueis the category's vertical screen position.state.y[key].value.valueis the numeric series value.state.y[key].position.valueis the value's horizontal screen position.
For grouped horizontal bars, use HorizontalBarGroup. For stacked horizontal bars, use HorizontalStackedBar.