Skip to content
العربية
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
Signed contracts: plan and actual
QuarterActualPlan
Q1110120
Q2150140
Q3155160
Q4190180
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
Open tickets by city
CityNewWaiting for reply
Riyadh2412
Jeddah189
Dammam117
Makkah83
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", "بانتظار الرد") },
      ]}
    />
  );
}