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
| Month | Orders | Returns |
|---|---|---|
| Jan | 420 | 40 |
| Feb | 510 | 52 |
| Mar | 480 | 38 |
| Apr | 620 | 61 |
| May | 700 | 55 |
| Jun | 810 | 49 |
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
/>
);
}| Hour | CPU (%) |
|---|---|
| 00:00 | 22 |
| 01:00 | 18 |
| 02:00 | 15 |
| 03:00 | 20 |
| 04:00 | 35 |
| 05:00 | 52 |
| 06:00 | 64 |
| 07:00 | 71 |
| 08:00 | 88 |
| 09:00 | 96 |
| 10:00 | 92 |
| 11:00 | 85 |
| 12:00 | 78 |
| 13:00 | 82 |
| 14:00 | 90 |
| 15:00 | 97 |
| 16:00 | 99 |
| 17:00 | 86 |
| 18:00 | 70 |
| 19:00 | 55 |
| 20:00 | 41 |
| 21:00 | 33 |
| 22:00 | 28 |
| 23:00 | 24 |
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}`) })}
/>
);
}