Charts
BarChart
Compares values by category: vertical or horizontal bars, grouped or stacked. Bars after the first series are hatched; patterns={false} removes the hatches when the brand colours differ enough.
import { BarChart } from "@percentsa/ui";Examples
- Actual
- Plan
| Quarter | Actual | Plan |
|---|---|---|
| Q1 | 110 | 120 |
| Q2 | 150 | 140 |
| Q3 | 155 | 160 |
| Q4 | 190 | 180 |
Code
export function BarChartExample() {
const t = useT();
const plan = [120, 140, 160, 180];
const actual = [110, 150, 155, 190];
return (
<BarChart
className="w-full"
title={t("Signed contracts: plan and actual", "العقود الموقعة: المخطط والفعلي")}
data={[1, 2, 3, 4].map((n, i) => ({ q: t(`Q${n}`, `الربع ${n}`), plan: plan[i]!, actual: actual[i]! }))}
x="q"
xLabel={t("Quarter", "الربع")}
series={[
{ key: "actual", label: t("Actual", "الفعلي") },
{ key: "plan", label: t("Plan", "المخطط") },
]}
/>
);
}- New
- Waiting for reply
| City | New | Waiting for reply |
|---|---|---|
| Riyadh | 24 | 12 |
| Jeddah | 18 | 9 |
| Dammam | 11 | 7 |
| Makkah | 8 | 3 |
Code
export function BarChartHorizontalExample() {
const t = useT();
return (
<BarChart
className="w-full"
layout="horizontal"
stacked
title={t("Open tickets by city", "التذاكر المفتوحة حسب المدينة")}
data={[
{ city: t("Riyadh", "الرياض"), new: 24, waiting: 12 },
{ city: t("Jeddah", "جدة"), new: 18, waiting: 9 },
{ city: t("Dammam", "الدمام"), new: 11, waiting: 7 },
{ city: t("Makkah", "مكة"), new: 8, waiting: 3 },
]}
x="city"
xLabel={t("City", "المدينة")}
series={[
{ key: "new", label: t("New", "جديدة") },
{ key: "waiting", label: t("Waiting for reply", "بانتظار الرد") },
]}
/>
);
}