sgds-data-visualisation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSGDS Data Visualisation Pattern
SGDS 数据可视化模式
SGDS does not bundle a charting library. For data visualisation, use Apache ECharts and apply the SGDS colour palette so charts remain visually consistent with your design system.
SGDS 并未捆绑任何图表库。进行数据可视化时,请使用 Apache ECharts 并应用SGDS调色板,确保图表与你的设计系统在视觉上保持一致。
Prerequisites
前提条件
- Complete base project setup per sgds-getting-started.
- Install and configure ECharts independently — see https://echarts.apache.org/.
- 已按照 sgds-getting-started 完成基础项目设置。
- 独立安装并配置ECharts —— 详见 https://echarts.apache.org/。
Installing ECharts
安装ECharts
ECharts is not included in . Install it separately:
@govtechsg/sgds-web-componentbash
npm install echartsThen import and initialise per the ECharts getting started guide:
js
import * as echarts from "echarts";
const chart = echarts.init(document.getElementById("chart"));
chart.setOption(option);ECharts 未包含在 中,需单独安装:
@govtechsg/sgds-web-componentbash
npm install echarts然后按照 ECharts 入门指南 进行导入和初始化:
js
import * as echarts from "echarts";
const chart = echarts.init(document.getElementById("chart"));
chart.setOption(option);SGDS Colour Palette for ECharts
适用于ECharts的SGDS调色板
Apply the SGDS palette by setting the array in your chart option. The values below are the raw hex values of the SGDS data-visualisation primitive tokens:
color| Token | Hex |
|---|---|
| |
| |
| |
| |
| |
通过在图表配置项中设置 数组来应用SGDS调色板。以下是SGDS数据可视化基础令牌的原始十六进制值:
color| 令牌 | 十六进制值 |
|---|---|
| |
| |
| |
| |
| |
Per-chart (recommended)
单图表配置(推荐)
Set directly in the chart option. ECharts cycles through the colours sequentially across series:
colorjs
const option = {
color: ["#ac1cdb", "#00758d", "#0e7c3d", "#0269d0", "#7e6917"],
// ... rest of chart option
};直接在图表配置项中设置 。ECharts会按顺序在各系列中循环使用这些颜色:
colorjs
const option = {
color: ["#ac1cdb", "#00758d", "#0e7c3d", "#0269d0", "#7e6917"],
// ... 其余图表配置项
};Global theme (all charts on the page)
全局主题(页面所有图表)
Register a named theme once at app startup, then pass the theme name when initialising each chart:
js
import * as echarts from "echarts";
echarts.registerTheme("sgds", {
color: ["#ac1cdb", "#00758d", "#0e7c3d", "#0269d0", "#7e6917"],
});
const chart = echarts.init(document.getElementById("chart"), "sgds");在应用启动时注册一个命名主题,然后在初始化每个图表时传入主题名称:
js
import * as echarts from "echarts";
echarts.registerTheme("sgds", {
color: ["#ac1cdb", "#00758d", "#0e7c3d", "#0269d0", "#7e6917"],
});
const chart = echarts.init(document.getElementById("chart"), "sgds");For AI Agents
针对AI Agent的说明
- ECharts is not provided by SGDS — always tell users to install it separately from https://echarts.apache.org/.
- The five SGDS palette colours are fixed hex values taken from the primitive tokens. Do not reference CSS variables inside the ECharts array — ECharts does not resolve CSS custom properties.
color - For a single chart, set in the option object. For multiple charts sharing the same palette, use
coloronce at app startup.echarts.registerTheme() - Palette order: purple → cyan → green → blue → yellow. ECharts cycles through them automatically across series.
- ECharts 并非由SGDS提供 —— 务必告知用户需从 https://echarts.apache.org/ 单独安装。
- SGDS调色板的五种颜色是取自基础令牌的固定十六进制值。请勿在ECharts的 数组中引用CSS变量 —— ECharts无法解析CSS自定义属性。
color - 单个图表可在配置对象中设置 ;若多个图表共享同一调色板,请在应用启动时调用一次
color。echarts.registerTheme() - 调色板顺序:紫色 → 青色 → 绿色 → 蓝色 → 黄色。ECharts会自动在各系列中循环使用这些颜色。