返回 Skill 列表
extension
分类: 开发与工程无需 API Key

vega

使用Vega-Lite(简单)和Vega(高级)创建数据驱动的图表。最适合条形图、折线图、散点图、热力图、面积图以及多系列分析。当您拥有需要统计可视化的数值数据数组时,请使用它。Vega适用于雷达图和词云。不适用于流程图(请使用mermaid)或快速KPI卡片(请使用信息图)。

person作者: jakexiaohubgithub

Vega / Vega-Lite Visualizer

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 ```vega-lite or ```vega fence. Always include $schema, 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.


Critical Syntax Rules

Rule 1: Always Include Schema

"$schema": "https://vega.github.io/schema/vega-lite/v5.json"

Rule 2: Valid JSON Only

❌ {field: "x",}     → Trailing comma, unquoted key
✅ {"field": "x"}    → Proper JSON

Rule 3: Field Names Must Match Data

❌ "field": "Category"  when data has "category"
✅ "field": "category"  → Case-sensitive match

Rule 4: Type Must Be Valid

✅ quantitative | nominal | ordinal | temporal
❌ numeric | string | date

Common Pitfalls

| Issue | Solution | |-------|----------| | Chart not rendering | Check JSON validity, verify $schema | | 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 resolve: {scale: {y: "independent"}} |


Output Format

```vega-lite
{...}
```

Or for full Vega:

```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