ข้ามไปยังเนื้อหา

มาตรวัด

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="คงเหลือ"
/>

พร้อมข้อความใต้มาตร

footer แสดงใต้มาตร เช่น ห่างจากเป้าเท่าใด รับข้อความหรือโหนดก็ได้

เบิกจ่ายเทียบเป้าไตรมาส
เบิกจ่ายคงเหลือ
สูงกว่าเป้า 6 จุด
<GaugeChart
  title="เบิกจ่ายเทียบเป้าไตรมาส"
  label="เบิกจ่าย"
  value={81}
  target={75}
  targetLabel="ถึงเป้า"
  restLabel="คงเหลือ"
  footer="สูงกว่าเป้า 6 จุด"
/>

props ทั้งหมด

ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้

GaugeChart 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 "เป้า".
restLabelstring—Names the rest past the target in the legend, such as "คงเหลือ". Leave it out to leave it out of the legend.
captionstring—Under the figure inside the ring. The target by default, such as "เป้า 75%".

ข้อควรปฏิบัติ

  • value และ target เป็นเปอร์เซ็นต์ระหว่าง 0 ถึง 100
  • มาตรนี้ไม่มีมุมมองตาราง ค่าและเป้าแสดงเป็นตัวเลขบนมาตร และ label ใช้เป็นชื่อสำหรับโปรแกรมอ่านหน้าจอ
  • หน้าที่มีกราฟต้องวาง <ChartPaints /> หนึ่งครั้ง ไม่เช่นนั้นมาตรจะไม่มีสี
  • ส่ง title label targetLabel restLabel caption และ footer ในภาษาของหน้าจออยู่แล้ว แอปแปลเองด้วยไฟล์ข้อความของแอป เช่น t() ของ next-intl
  • ข้อมูลในตัวอย่างและการทดสอบต้องเป็นข้อมูลสมมติ

ซอร์สโค้ด: ui/src/charts/target.tsx