Bar Chart
Compare values across categories with vertical and horizontal bars.
Default
app/chart-demo.tsx
import { BarChart } from "@/components/ui/bar-chart";
const data = [
{ label: "Jan", value: 186 },
{ label: "Feb", value: 305 },
{ label: "Mar", value: 237 },
{ label: "Apr", value: 173 },
{ label: "May", value: 409 },
{ label: "Jun", value: 214 },
];
export function MyBarChart() {
return <BarChart data={data} color="#2563eb" />;
}Installation
npx @aniui/cli add bar-chartHorizontal
Bars rendered horizontally.
import { BarChart } from "@/components/ui/bar-chart";
export function HorizontalBarChart() {
return <BarChart data={data} horizontal showLabels />;
}Stacked
Multiple series stacked on top of each other.
import { BarChart } from "@/components/ui/bar-chart";
const grouped = [
{ key: "desktop", color: "#2563eb" },
{ key: "mobile", color: "#f97316" },
];
const groupedData = [
{ label: "Jan", values: [186, 120] },
{ label: "Feb", values: [305, 210] },
];
// Use stacked bars by passing grouped + groupedData
export function StackedBarChart() {
return <BarChart data={[]} grouped={grouped} groupedData={groupedData} />;
}Grouped
Multiple series displayed side by side.
import { BarChart } from "@/components/ui/bar-chart";
// Grouped bars side by side
export function GroupedBarChart() {
return (
<BarChart
data={[]}
grouped={grouped}
groupedData={groupedData}
showLabels
/>
);
}Negative Values
Bars that extend below the baseline for negative values.
import { BarChart } from "@/components/ui/bar-chart";
const data = [
{ label: "Jan", value: 186 },
{ label: "Feb", value: -80 },
{ label: "Mar", value: 237 },
{ label: "Apr", value: -50 },
];
// Negative values render below the baseline
export function NegativeBarChart() {
return <BarChart data={data} />;
}With Labels
Bar chart with axis labels, grid lines, and tooltip.
import { BarChart } from "@/components/ui/bar-chart";
export function BarChartWithLabels() {
return (
<BarChart
data={data}
showGrid
showLabels
height={220}
/>
);
}Props
PropTypeDefault
data{ label: string; value: number; color?: string }[]—heightnumber200colorstring"#2563eb"horizontalbooleanfalseshowGridbooleantrueshowLabelsbooleanfalsebarRadiusnumber4grouped{ key, color }[]—groupedData{ label, values[] }[]—classNamestring—