Skip to content
العربية
Charts

LineChart

Values over time as lines. Series take the brand chart colours (--p-chart-1 to --p-chart-5; default greys) and also differ by dash pattern and marker shape; patterns={false} removes the dashes. In Arabic time runs from right to left. Focus the chart and use the arrow keys to read each value. limit draws a dashed line with its label; a value at 90 % of the limit or more shows in the warning colour. With onSelectPoint, a click or Enter on the chosen point opens it. On touch, the first tap shows the value and a second tap on the same point opens it. The limit label has a halo in --p-chart-surface (default the page colour; Card sets it to its own surface), so it stays readable over the line.

import { LineChart, type ChartLimit, type ChartSeries } from "@percentsa/ui";

Examples

  • Orders
  • Returns
Orders and returns by month
MonthOrdersReturns
Jan42040
Feb51052
Mar48038
Apr62061
May70055
Jun81049
Code
export function LineChartExample() {
  const t = useT();
  const orders = [420, 510, 480, 620, 700, 810];
  const returns = [40, 52, 38, 61, 55, 49];
  return (
    <LineChart
      className="w-full"
      title={t("Orders and returns by month", "الطلبات والمرتجعات حسب الشهر")}
      data={MONTHS[useLang()].map((month, i) => ({ month, orders: orders[i]!, returns: returns[i]! }))}
      x="month"
      xLabel={t("Month", "الشهر")}
      series={[
        { key: "orders", label: t("Orders", "الطلبات") },
        { key: "returns", label: t("Returns", "المرتجعات") },
      ]}
      curve="monotone"
      markers
    />
  );
}
CPU use by hour
HourCPU (%)
00:0022
01:0018
02:0015
03:0020
04:0035
05:0052
06:0064
07:0071
08:0088
09:0096
10:0092
11:0085
12:0078
13:0082
14:0090
15:0097
16:0099
17:0086
18:0070
19:0055
20:0041
21:0033
22:0028
23:0024

Limit 1 CPU

Press Enter to open the chosen point.

Code
export function LineChartLimitExample() {
  const t = useT();
  const cpu = [22, 18, 15, 20, 35, 52, 64, 71, 88, 96, 92, 85, 78, 82, 90, 97, 99, 86, 70, 55, 41, 33, 28, 24];
  return (
    <LineChart
      className="w-full"
      title={t("CPU use by hour", "استخدام المعالج حسب الساعة")}
      data={cpu.map((v, h) => ({ hour: `${String(h).padStart(2, "0")}:00`, cpu: v }))}
      x="hour"
      xLabel={t("Hour", "الساعة")}
      series={[{ key: "cpu", label: t("CPU (%)", "المعالج (%)") }]}
      limit={{ value: 100, label: t("Limit 1 CPU", "الحد: معالج واحد") }}
      onSelectPoint={(hour) => toast({ title: t(`Opened ${hour}`, `تم فتح ${hour}`) })}
    />
  );
}