设计原则
数据可视化的可信度不仅来自图形,还来自可解释的数据转换链。每个聚合、过滤和派生字段都应能追溯。
大理论
同一份原始数据经过不同 filter、aggregate、bin、timeUnit、join、stack、sort 和缺失值处理,会得到完全不同的图表结论。Agent 生成 dashboard 时如果只保存最终数组或 SVG,未来维护者无法判断图表是否使用了正确时间窗、是否把 null 当 0、是否按错误维度聚合。可视化条目需要像代码一样保存 transform provenance。
小知识点
- Filter 要记录字段、条件、默认值、用户可见状态和 URL/query state;隐藏过滤会破坏信任。
- Aggregate 要记录 groupBy、measure、function、count/sum/avg/median/max/min、是否加权和是否去重。
- Bin/timeUnit 会改变读数粒度;日期按天、周、月聚合时必须说明时区和周起始日。
- Missing value 不能随手变 0;要区分 unknown、not applicable、zero、filtered out 和 data delayed。
- Sort 会暗示优先级;排序字段、方向和 tie-breaker 应可解释。
- 前端库 spec、SQL、API 参数和图表说明应保持同一 transform 口径。
设计判断
如果图表旁边或详情中能解释数据从哪里来、如何过滤、如何聚合、何时更新、哪些值缺失,以及用户改变筛选会如何影响结果,这张图才具备审计性。无法解释转换链的图表不应被用于决策。
实现建议
为图表建立 transform record:source、query/filter、groupBy、aggregate、bin/timeUnit、calculated fields、join、missingValuePolicy、sort、sampleSize、updatedAt、owner、specHref 和 validation notes。使用 Vega-Lite 或 Observable Plot 时保留可读 spec;自写 D3/React 图表也要把 transform 写成可测试纯函数,并在 UI 中暴露简短 methodology。
反例/风险
API 返回已聚合数据但前端不知道口径、null 被 chart library 断线或归零却无说明、筛选器 URL 和图表数据不一致、同比计算跨时区错误、排序 tie-breaker 不稳定导致截图跳动、导出 CSV 与图表不是同一数据集。
案例分析
Vega-Lite 文档把 transform 分为 view-level transforms 与 encoding field transforms,并支持 aggregate、filter、bin、timeUnit、sort、stack 等声明式转换;Observable Plot 面向 tabular data 和 exploratory analysis,强调 marks、scales 和 layered grammar。可学习点是:把转换写成可读 spec 或可测试函数,图表才可复查、可复现、可被 agent 安全改写。
来源链接
Vega-Lite Transformation: https://vega.github.io/vega-lite/docs/transform.html Vega-Lite Aggregate: https://vega.github.io/vega-lite/docs/aggregate.html Vega-Lite Filter: https://vega.github.io/vega-lite/docs/filter.html Observable Plot What is Plot: https://observablehq.com/plot/what-is-plot USWDS Data Visualizations: https://designsystem.digital.gov/components/data-visualizations/
Agent 指令
生成图表前必须输出 transform provenance,包含 filter、aggregate、timeUnit/bin、missing value、sort 和 source;禁止只保存最终图形或样式。