กราฟเส้น
LineChart
Values over time as a line, area or step chart, with a style switch. Series are drawn in array order, so the last one sits on top and gets the area fill. The legend and tooltip list series from the top down.
ใช้แสดงค่าที่เปลี่ยนตามเวลา เช่น การเบิกจ่ายรายเดือน ส่งป้ายแกน x ชุดข้อมูล ค่าสูงสุด และเส้นแบ่งแกน y กราฟมีปุ่มสลับรูปแบบ และตารางข้อมูลสำหรับโปรแกรมอ่านหน้าจอ
import { LineChart } from "@bsru/ui";ตัวอย่าง
แผนเทียบผลจริง
ชุดข้อมูลวาดตามลำดับในอาร์เรย์ ชุดสุดท้ายอยู่บนสุด
ผลจริงแผน
ดูข้อมูลเป็นตาราง
| เดือน | แผน | จริง |
|---|---|---|
| ต.ค. | 5 | 3.2 |
| พ.ย. | 11 | 7 |
| ธ.ค. | 17 | 11.1 |
| ม.ค. | 24 | 16.3 |
| ก.พ. | 31 | 20.9 |
| มี.ค. | 39 | 26.8 |
| เม.ย. | 47 | 33.2 |
| พ.ค. | 54 | 38.3 |
| มิ.ย. | 61 | 44.1 |
| ก.ค. | 67 | 50.8 |
| ส.ค. | 72 | 58 |
| ก.ย. | 76 | 64.8 |
<LineChart
title="การเบิกจ่ายสะสมเทียบแผน (ล้านบาท)"
ariaLabel="แผนและผลการเบิกจ่ายสะสม"
labels={[
"ต.ค.",
"พ.ย.",
"ธ.ค.",
"ม.ค.",
"ก.พ.",
"มี.ค.",
"เม.ย.",
"พ.ค.",
"มิ.ย.",
"ก.ค.",
"ส.ค.",
"ก.ย.",
]}
labelHead="เดือน"
max={80}
ticks={[0, 20, 40, 60, 80]}
series={[
{
name: "แผน",
label: "แผน",
tip: "แผน",
paint: 1,
dashed: true,
values: [5, 11, 17, 24, 31, 39, 47, 54, 61, 67, 72, 76],
},
{
name: "ผลจริง",
label: "จริง",
tip: "จริง",
paint: 0,
values: [3.2, 7, 11.1, 16.3, 20.9, 26.8, 33.2, 38.3, 44.1, 50.8, 58, 64.8],
},
]}
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| title* จำเป็น | "การเบิกจ่ายสะสมเทียบแผน (ล้านบาท)" | string | The chart's caption. |
| ariaLabel* จำเป็น | "แผนและผลการเบิกจ่ายสะสม" | string | Names the drawing for screen readers. |
| labels* จำเป็น | รายการ 12 รายการ[ "ต.ค.", "พ.ย.", "ธ.ค.", "ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", ] | readonly string[] | One label per point, such as month names. |
| labelHead* จำเป็น | "เดือน" | string | Table header for the label column. |
| max* จำเป็น | 80 | number | Top of the value axis. |
| ticks* จำเป็น | [0, 20, 40, 60, 80] | readonly number[] | Values for the axis grid lines, from 0 up to max. |
| series* จำเป็น | รายการ 2 รายการ[
{
name: "แผน",
label: "แผน",
tip: "แผน",
paint: 1,
dashed: true,
values: [5, 11, 17, 24, 31, 39, 47, 54, 61, 67, 72, 76],
},
{
name: "ผลจริง",
label: "จริง",
tip: "จริง",
paint: 0,
values: [3.2, 7, 11.1, 16.3, 20.9, 26.8, 33.2, 38.3, 44.1, 50.8, 58, 64.8],
},
] | readonly LineSeries[] | The lines, drawn in array order. At most four. |
เริ่มเป็นกราฟพื้นที่
initialStyle เลือกรูปแบบแรก ผู้ใช้ยังสลับเองได้
ผลจริงแผน
ดูข้อมูลเป็นตาราง
| เดือน | แผน | จริง |
|---|---|---|
| ต.ค. | 5 | 3.2 |
| พ.ย. | 11 | 7 |
| ธ.ค. | 17 | 11.1 |
| ม.ค. | 24 | 16.3 |
| ก.พ. | 31 | 20.9 |
| มี.ค. | 39 | 26.8 |
| เม.ย. | 47 | 33.2 |
| พ.ค. | 54 | 38.3 |
| มิ.ย. | 61 | 44.1 |
| ก.ค. | 67 | 50.8 |
| ส.ค. | 72 | 58 |
| ก.ย. | 76 | 64.8 |
<LineChart
title="การเบิกจ่ายสะสมเทียบแผน (ล้านบาท)"
ariaLabel="แผนและผลการเบิกจ่ายสะสม"
labels={[
"ต.ค.",
"พ.ย.",
"ธ.ค.",
"ม.ค.",
"ก.พ.",
"มี.ค.",
"เม.ย.",
"พ.ค.",
"มิ.ย.",
"ก.ค.",
"ส.ค.",
"ก.ย.",
]}
labelHead="เดือน"
max={80}
ticks={[0, 20, 40, 60, 80]}
series={[
{
name: "แผน",
label: "แผน",
tip: "แผน",
paint: 1,
dashed: true,
values: [5, 11, 17, 24, 31, 39, 47, 54, 61, 67, 72, 76],
},
{
name: "ผลจริง",
label: "จริง",
tip: "จริง",
paint: 0,
values: [3.2, 7, 11.1, 16.3, 20.9, 26.8, 33.2, 38.3, 44.1, 50.8, 58, 64.8],
},
]}
initialStyle="area"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| title* จำเป็น | "การเบิกจ่ายสะสมเทียบแผน (ล้านบาท)" | string | The chart's caption. |
| ariaLabel* จำเป็น | "แผนและผลการเบิกจ่ายสะสม" | string | Names the drawing for screen readers. |
| labels* จำเป็น | รายการ 12 รายการ[ "ต.ค.", "พ.ย.", "ธ.ค.", "ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", ] | readonly string[] | One label per point, such as month names. |
| labelHead* จำเป็น | "เดือน" | string | Table header for the label column. |
| max* จำเป็น | 80 | number | Top of the value axis. |
| ticks* จำเป็น | [0, 20, 40, 60, 80] | readonly number[] | Values for the axis grid lines, from 0 up to max. |
| series* จำเป็น | รายการ 2 รายการ[
{
name: "แผน",
label: "แผน",
tip: "แผน",
paint: 1,
dashed: true,
values: [5, 11, 17, 24, 31, 39, 47, 54, 61, 67, 72, 76],
},
{
name: "ผลจริง",
label: "จริง",
tip: "จริง",
paint: 0,
values: [3.2, 7, 11.1, 16.3, 20.9, 26.8, 33.2, 38.3, 44.1, 50.8, 58, 64.8],
},
] | readonly LineSeries[] | The lines, drawn in array order. At most four. |
| initialStyle | "area" | LineStyle ค่าที่ใช้ได้: "line""area""step" | The style shown first. People can still switch. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| title* จำเป็น | string | — | The chart's caption. |
| ariaLabel* จำเป็น | string | — | Names the drawing for screen readers. |
| labels* จำเป็น | readonly string[] | — | One label per point, such as month names. |
| labelHead* จำเป็น | string | — | Table header for the label column. |
| series* จำเป็น | readonly LineSeries[] | — | The lines, drawn in array order. At most four. |
| max* จำเป็น | number | — | Top of the value axis. |
| ticks* จำเป็น | readonly number[] | — | Values for the axis grid lines, from 0 up to max. |
| initialStyle | LineStyle ค่าที่ใช้ได้: "line""area""step" | "line" | The style shown first. People can still switch. |
ชนิดข้อมูล
LineSeries
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| name* จำเป็น | string | — | Legend name, such as "ผลจริง". |
| label* จำเป็น | string | — | Short name for the end label and the table column, such as "จริง". |
| tip* จำเป็น | string | — | Word before the value in the tooltip, such as "จริง" / "actual". |
| values* จำเป็น | readonly number[] | — | One value per label, in the same order. |
| paint* จำเป็น | number | — | Series colour, 0 to 3. |
| dashed | boolean | — | Draws the line dashed, such as for a plan. |
| format | (v: number) => string | — | Formats the values in the tooltip and table. |
LineStyle
How the series are drawn: lines, lines with the top series filled, or steps.
type LineStyle = "line" | "area" | "step";ข้อควรปฏิบัติ
- values ของทุกชุดต้องยาวเท่ากับ labels
- หน้าที่มีกราฟต้องวาง <ChartPaints /> หนึ่งครั้ง ไม่เช่นนั้นเส้นจะไม่มีสี
- ส่งข้อความทุกตัวในภาษาของหน้าจออยู่แล้ว แอปแปลเองด้วยไฟล์ข้อความของแอป เช่น t() ของ next-intl ส่วนคำของกราฟเอง เช่น ปุ่มสลับรูปแบบ เปลี่ยนตาม LangProvider
- ข้อมูลในตัวอย่างและการทดสอบต้องเป็นข้อมูลสมมติ
ซอร์สโค้ด: ui/src/charts/line.tsx