มาตรวัด
GaugeChart
One percentage against a target, as a thick half ring: the result in the brand colour, the stretch still to go to the target in its darkest shade, and the rest past the target in diagonal lines. The figure sits inside.
ใช้แสดงตัวเลขเปอร์เซ็นต์เดียวเทียบเป้า เช่น การเบิกจ่ายของไตรมาส ถ้ามีหลายหน่วยงานเทียบเป้าเดียวกัน ใช้ BulletChart ถ้าเป็นความคืบหน้าทั่วไปที่ไม่มีเป้า ใช้ ProgressBar หรือ ProgressRing
import { GaugeChart } from "@bsru/ui";ตัวอย่าง
ต่ำกว่าเป้า
value และ target เป็นเปอร์เซ็นต์ 0 ถึง 100 ผลอยู่ในสีของแอป ช่วงที่ยังต้องไปให้ถึงเป้าเป็นสีเข้มที่สุด และส่วนที่เกินเป้าเป็นเส้นทแยง restLabel ใส่ส่วนนั้นในคำอธิบายสี
<GaugeChart
title="เบิกจ่ายเทียบเป้าไตรมาส"
label="เบิกจ่าย"
value={62}
target={75}
targetLabel="ถึงเป้า"
restLabel="คงเหลือ"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| title* จำเป็น | "เบิกจ่ายเทียบเป้าไตรมาส" | string | The chart's caption. |
| label* จำเป็น | "เบิกจ่าย" | string | Names the result, in the legend, the tooltip and for screen readers, such as "เบิกจ่าย". |
| value* จำเป็น | 62 | number | The result in %, from 0 to 100. |
| target* จำเป็น | 75 | number | The target in %, from 0 to 100. The stretch from the result up to it is dark. |
| targetLabel* จำเป็น | "ถึงเป้า" | string | Names the target, in the legend and the tooltip, such as "เป้า". |
| restLabel | "คงเหลือ" | string | Names the rest past the target in the legend, such as "คงเหลือ". Leave it out to leave it out of the legend. |
พร้อมข้อความใต้มาตร
footer แสดงใต้มาตร เช่น ห่างจากเป้าเท่าใด รับข้อความหรือโหนดก็ได้
<GaugeChart
title="เบิกจ่ายเทียบเป้าไตรมาส"
label="เบิกจ่าย"
value={81}
target={75}
targetLabel="ถึงเป้า"
restLabel="คงเหลือ"
footer="สูงกว่าเป้า 6 จุด"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| title* จำเป็น | "เบิกจ่ายเทียบเป้าไตรมาส" | string | The chart's caption. |
| label* จำเป็น | "เบิกจ่าย" | string | Names the result, in the legend, the tooltip and for screen readers, such as "เบิกจ่าย". |
| value* จำเป็น | 81 | number | The result in %, from 0 to 100. |
| target* จำเป็น | 75 | number | The target in %, from 0 to 100. The stretch from the result up to it is dark. |
| targetLabel* จำเป็น | "ถึงเป้า" | string | Names the target, in the legend and the tooltip, such as "เป้า". |
| restLabel | "คงเหลือ" | string | Names the rest past the target in the legend, such as "คงเหลือ". Leave it out to leave it out of the legend. |
| footer | "สูงกว่าเป้า 6 จุด" | ReactNode | Under the gauge, such as how far it is from target. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| title* จำเป็น | string | — | The chart's caption. |
| label* จำเป็น | string | — | Names the result, in the legend, the tooltip and for screen readers, such as "เบิกจ่าย". |
| value* จำเป็น | number | — | The result in %, from 0 to 100. |
| target* จำเป็น | number | — | The target in %, from 0 to 100. The stretch from the result up to it is dark. |
| targetLabel* จำเป็น | string | — | Names the target, in the legend and the tooltip, such as "เป้า". |
| restLabel | string | — | Names the rest past the target in the legend, such as "คงเหลือ". Leave it out to leave it out of the legend. |
| caption | string | — | Under the figure inside the ring. The target by default, such as "เป้า 75%". |
| footer | ReactNode | — | Under the gauge, such as how far it is from target. |
ข้อควรปฏิบัติ
- value และ target เป็นเปอร์เซ็นต์ระหว่าง 0 ถึง 100
- มาตรนี้ไม่มีมุมมองตาราง ค่าและเป้าแสดงเป็นตัวเลขบนมาตร และ label ใช้เป็นชื่อสำหรับโปรแกรมอ่านหน้าจอ
- หน้าที่มีกราฟต้องวาง <ChartPaints /> หนึ่งครั้ง ไม่เช่นนั้นมาตรจะไม่มีสี
- ส่ง title label targetLabel restLabel caption และ footer ในภาษาของหน้าจออยู่แล้ว แอปแปลเองด้วยไฟล์ข้อความของแอป เช่น t() ของ next-intl
- ข้อมูลในตัวอย่างและการทดสอบต้องเป็นข้อมูลสมมติ
ซอร์สโค้ด: ui/src/charts/target.tsx