agentleFS
OugeXOugeX/dsh-web-dev-mode/skills/data-visualization/SKILL.md

data-visualization

Skill0 starsChanged 14 days agoMITView on GitHub

数据可视化与图表的选型与规范。包含图表类型决策树(趋势/对比/占比/分布/关系)、饼图与环形图的使用边界、双 Y 轴的禁忌、色板(分类色/连续色/语义色)与色盲友好、坐标轴与网格线规范、数字与单位格式化、空数据与加载中与错误三态、响应式与深色模式、柱状图基线必须为 0、动效克制。当要做仪表盘、选图表类型、调图表配色、或发现图表误导读者时使用。

48 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use case-study-writing, loading-states and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • CAPP-FinancialsSkill

    case-study-writing

    Client case study with challenge-approach-solution-impact structure and quantified outcomes

    Also in 3 projects that use this

  • soilmassSkill

    loading-states

    Animation patterns for loading, progress, and waiting states. Use for skeleton screens, progress indicators, optimistic UI, and content placeholder transitions. Keeps users informed and engaged during async operations.

    Also in 3 projects that use this

  • nddqSkill

    dashboard-design

    Also in 4 projects that use this

  • launchapp-devSkill

    interview-script

    Create a structured user interview script with warm-up, core exploration, and wrap-up sections. Use when preparing for user research interviews to ensure consistent, insightful conversations.

    Also in 3 projects that use this

  • nandanosqlSkill

    swot-analysis

    Conduct a structured SWOT analysis — Strengths, Weaknesses, Opportunities, Threats — that connects internal capabilities to external forces for strategic decision-making.

    Also in 3 projects that use this

  • abinauvSkill

    change-management

    Comprehensive change management consulting toolkit — stakeholder mapping, ADKAR framework, Kotter's 8-Step Model, communication planning, resistance analysis, cultural assessment, readiness assessment, training needs analysis, impact assessment, and transition planning.

    Also in 3 projects that use this

The file

Files
SKILL.md

定位:图表的第一目标是准确,不是好看

一张误导的图表比没有图表更糟。 所有选型和样式决策都要先过这一关。


一、图表选型决策树

你的数据要回答什么问题?
│
├─ 随时间怎么变?              → 折线图 / 面积图
├─ 各项之间谁大谁小?          → 柱状图(横向或纵向)
├─ 各部分占整体的比例?        → 堆叠柱 / 环形图(饼图慎用)
├─ 数据分布长什么样?          → 直方图 / 箱线图 / 散点图
├─ 两个变量有关系吗?          → 散点图
├─ 多层级占比?                → 矩形树图 / 旭日图
├─ 流程与转化?                → 漏斗图
└─ 单一核心指标?              → 大数字 + 迷你趋势线(不要图表)

各类型的硬约束

类型约束
折线图时间必须连续且有顺序;不要用折线连类别数据
柱状图基线必须为 0,否则视觉上会夸大差异
饼图/环形图分类 ≤ 5;超过 5 类改用条形图或堆叠柱
散点图点数 > 500 时开降采样或透明度
双 Y 轴禁止(除非两个指标单位确实不同且已明确标注)

为什么饼图要限制在 5 类以内

人眼对角度差异的分辨能力很差。6 个以上的扇区,用户只能靠颜色和标签去对,读不出比例差异。

超过 5 类时:

  • 前 4 类 + 「其他」合并
  • 或改用横向条形图(长度比角度好判断得多)

二、必须避免的误导

反模式为什么错正确做法
柱状图基线不为 0视觉差异被放大数倍Y 轴从 0 开始
折线图 Y 轴不从 0 开始可以接受,但要明显标注若不从 0,加断轴标记或注释
双 Y 轴两条线的交叉点毫无意义,但读者会解读为"相关"拆成两张图,或归一化为百分比
3D 图表透视扭曲比例,纯装饰一律 2D
只靠颜色区分系列色盲用户无法区分加线型/标记/直接标注
面积图叠加后画的遮挡前面的用堆叠面积图或透明度
截断的时间轴缺失时间段会让趋势失真补齐缺失点或明确标注
平滑曲线过度插值出实际不存在的数据点用直线连接,或标注"趋势线"

三、色板

3.1 三类色板,各管一件事

类型用途例
分类色(Categorical)区分不同系列8 色循环色板
连续色(Sequential)表示数值大小浅蓝 → 深蓝
发散色(Diverging)有正负/中心的数值红 → 白 → 蓝

3.2 推荐色板(色盲友好)

分类色(8 色,基于 Okabe-Ito,色盲安全):
#0072B2  蓝
#E69F00  橙
#009E73  绿
#CC79A7  紫红
#56B4E9  浅蓝
#D55E00  朱红
#F0E442  黄
#999999  灰

不要用红绿对比做主色区分(红绿色盲占男性 8%)。

3.3 语义色(固定含义,不要乱用)

含义色
正向/成功绿 #52c41a
负向/危险红 #ff4d4f
警告橙 #faad14
中性/信息蓝 #1677ff

语义色不能用于分类——红色永远表示"坏",不能拿来当"系列 3"。

3.4 系列数量与颜色

系列数处理
1–8用分类色板
9–12前 8 + 灰阶区分
> 12不要一张图放这么多系列,拆图或用小倍数图(small multiples)

四、坐标轴与网格

元素规范
Y 轴柱状图从 0 开始;折线图可不为 0 但要标注
X 轴标签时间密集时用间隔显示(每 3 个显示一个),不要全挤
网格线只画水平线,不画垂直线(噪音)
刻度数4–6 个,多了太密
轴标题单位不确定时必须标注(元 / 万 / %)
图例系列 ≤ 3 时可直接在线尾标注,省掉图例

五、数字与单位

场景规范
大数字千分位:1,234,567
超大数字缩写 + 单位:123.4 万 / 1.2 亿(中文习惯用「万」不是「K」)
金额两位小数 + 货币符号:¥12,890.00
百分比一位小数:23.5%
坐标轴缩写:0 / 50万 / 100万
小数点同一张图的小数位数必须统一

不要在同一张图里混用「1.2万」和「12000」。


六、三态:空、加载、错误

6.1 空数据

{data.length === 0 ? (
  <Empty
    description={hasFilter ? '没有符合条件的数据,试试调整筛选' : '暂无数据'}
    style={{ height: chartHeight, display: 'flex', alignItems: 'center', justifyContent: 'center' }}
  />
) : <Chart ... />}

必须占住图表高度,否则加载完成时布局会跳(见 async-loading-stability)。

区分两种空:

  • 从没有数据 → 「暂无数据」
  • 筛选后无结果 → 「没有符合条件的数据」

6.2 加载中

  • 用骨架画出坐标轴和网格,不要用 spinner 盖住空白
  • 或者用图表容器的 loading 遮罩(保留上一次的数据更有连续性)

6.3 出错

<Result status="error" title="数据加载失败" subTitle={err.message}
        extra={<Button onClick={refetch}>重试</Button>} />

6.4 数据不完整

部分数据缺失时(比如某天接口失败):

  • 不要把缺失点当 0(会画出假的下跌)
  • 折线图用 connectNulls: false,让线断开
  • 或加视觉标记(虚线那段表示估算)

七、响应式与深色模式

7.1 响应式

// 用 ResizeObserver,不要用 window.resize
const ref = useRef<HTMLDivElement>(null)
const [width, setWidth] = useState(0)
useEffect(() => {
  const ro = new ResizeObserver(([e]) => setWidth(e.contentRect.width))
  ro.observe(ref.current!); return () => ro.disconnect()
}, [])

图表宽度必须跟随容器,不要写死 width={800}。

容器宽度 < 480 时:

  • 图例移到下方
  • X 轴标签间隔加大
  • 考虑切换为更简单的图表类型

7.2 深色模式

// 色板要为深色单独准备,不要把浅色模式的颜色直接反色
const palette = isDark ? darkPalette : lightPalette

深色下:

  • 背景色 #141414,网格线 #303030
  • 亮色系列要降饱和,否则刺眼
  • 文字用 #d9d9d9 而非纯白

八、可访问性

  • 不要只靠颜色区分系列:加线型(实线/虚线)、标记形状(圆/方/三角)、直接标注
  • 图表要有 aria-label 描述核心结论
  • 提供数据表格作为替代(可折叠的 <Table>)
  • 色盲模拟检查(Chrome DevTools 有)

九、动效克制

  • 首次渲染:可以有 300–500ms 的绘制动画
  • 数据更新:不要每次刷新都重播入场动画,只更新数值
  • 切换指标时可以有过渡,但不要超过 400ms
  • 详见 motion-animation-spec

十、验收清单

  • 图表类型符合决策树,不是"凭感觉选的"
  • 柱状图基线为 0
  • 没有双 Y 轴
  • 饼图分类 ≤ 5
  • 没有 3D 图
  • 系列区分不只靠颜色(有线型/标记)
  • 语义色没有用于分类
  • Y 轴有单位标注
  • 大数字格式化且小数位统一
  • 空态区分「无数据」与「筛选无结果」,且占满图表高度
  • 加载用骨架而非空白 spinner
  • 缺数据不当 0 处理
  • 宽度用 ResizeObserver 跟随容器
  • 深色模式有独立色板
  • 有 aria-label 与数据表格替代

十一、反面清单

  1. ❌ 柱状图基线不为 0
  2. ❌ 双 Y 轴
  3. ❌ 8 类数据的饼图
  4. ❌ 3D 柱状图
  5. ❌ 用红色表示"系列 3"
  6. ❌ 只靠颜色区分系列
  7. ❌ 同一张图混用「1.2万」和「12000」
  8. ❌ 空数据时图表容器塌陷
  9. ❌ 缺失数据当 0(画出假下跌)
  10. ❌ 写死图表宽度
  11. ❌ 每次数据刷新重播入场动画
  12. ❌ Y 轴不写单位

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.