vega
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVega / Vega-Lite Visualizer
Vega / Vega-Lite 可视化工具
Quick Start: Structure data as array of objects → Choose mark type (bar/line/point/area/arc/rect) → Map encodings (x, y, color, size) to fields → Set data types (quantitative/nominal/ordinal/temporal) → Wrap in or fence. Always include , use valid JSON with double quotes, field names are case-sensitive. Use Vega-Lite for 90% of charts; Vega only for radar, word cloud, force-directed.
```vega-lite```vega$schema快速入门: 将数据整理为对象数组 → 选择标记类型(柱状/折线/点/面积/圆弧/矩形)→ 将编码(x、y、颜色、尺寸)映射到字段 → 设置数据类型(quantitative/nominal/ordinal/temporal)→ 用或代码块包裹。务必包含,使用双引号的有效JSON,字段名称区分大小写。90%的图表使用Vega-Lite即可;仅雷达图、词云图、力导向图需使用Vega。
```vega-lite```vega$schemaCritical Syntax Rules
关键语法规则
Rule 1: Always Include Schema
规则1:务必包含Schema
json
"$schema": "https://vega.github.io/schema/vega-lite/v5.json"json
"$schema": "https://vega.github.io/schema/vega-lite/v5.json"Rule 2: Valid JSON Only
规则2:仅使用有效JSON
❌ {field: "x",} → Trailing comma, unquoted key
✅ {"field": "x"} → Proper JSON❌ {field: "x",} → 多余逗号,未加引号的键
✅ {"field": "x"} → 正确的JSON格式Rule 3: Field Names Must Match Data
规则3:字段名称必须与数据匹配
❌ "field": "Category" when data has "category"
✅ "field": "category" → Case-sensitive match❌ "field": "Category" 而数据中是"category"
✅ "field": "category" → 区分大小写的精确匹配Rule 4: Type Must Be Valid
规则4:类型必须有效
✅ quantitative | nominal | ordinal | temporal
❌ numeric | string | date✅ quantitative | nominal | ordinal | temporal
❌ numeric | string | dateCommon Pitfalls
常见问题
| Issue | Solution |
|---|---|
| Chart not rendering | Check JSON validity, verify |
| Data not showing | Field names must match exactly |
| Wrong chart type | Match mark to data structure |
| Colors not visible | Check color scale contrast |
| Dual-axis issues | Add |
| 问题 | 解决方案 |
|---|---|
| 图表无法渲染 | 检查JSON有效性,验证 |
| 数据未显示 | 字段名称必须完全匹配 |
| 图表类型错误 | 标记类型需与数据结构匹配 |
| 颜色不可见 | 检查颜色刻度的对比度 |
| 双轴问题 | 添加 |
Output Format
输出格式
markdown
```vega-lite
{...}
```Or for full Vega:
markdown
```vega
{...}
```markdown
```vega-lite
{...}
```或者使用完整版Vega:
markdown
```vega
{...}
```Related Files
相关文件
For advanced chart patterns and complex visualizations, refer to references below:
- examples.md — Stacked bar, grouped bar, multi-series line, area, heatmap, radar (Vega), word cloud (Vega), and interactive chart examples
如需进阶图表模式和复杂可视化效果,请参考以下资料:
- examples.md — 包含堆叠柱状图、分组柱状图、多序列折线图、面积图、热力图、雷达图(Vega)、词云图(Vega)以及交互式图表示例