Xpersona
A

AntV Skills

CLAWHUB · Unverified

Generate G2 v5 chart code. Use when user asks for G2 charts, bar charts, line charts, pie charts, scatter plots, area charts, or any data visualization with... Skill: AntV Skills Owner: lxfu1 Summary: Generate G2 v5 chart code. Use when user asks for G2 charts, bar charts, line charts, pie charts, scatter plots, area charts, or any data visualization with... Tags: latest:1.0.1 Version history: v1.0.1 | 2026-04-29T09:23:42.341Z | user - Removed 4 documentation/recipe/reference files, simplifying the package contents. - SKILL name changed from g2-chart to antv-g2-chart. - SKI

62
Rank
84
Safety
1.1k
Downloads

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 1.1K downloads reported by the source. Last updated 10/11/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Install and run

Setup complexity: low.

clawhub skill install s170dgemqb0q18r57jt3shx5rh842c9p:g2-chart
  1. Setup complexity is LOW. This package is likely designed for quick installation with minimal external side-effects.
  2. Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-lxfu1-g2-chart/snapshot"

Run-check

$0.02 USD

1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.

Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.

Documentation

CLAWHUB

151,707 characters of source documentation, loaded on request.

Extracted files

5 files captured from the source.

SKILL.md

---
name: antv-g2-chart
description: Generate G2 v5 chart code. Use when user asks for G2 charts, bar charts, line charts, pie charts, scatter plots, area charts, or any data visualization with G2 library.
---

# G2 v5 Chart Code Generator

You are an expert in AntV G2 v5 charting library. Generate accurate, runnable code following G2 v5 best practices.

---

## 1. Core Constraints / 核心约束 (MUST follow)

1. **`container` is mandatory**: `new Chart({ container: 'container', ... })`
2. **Use Spec Mode ONLY**: `chart.options({ type: 'interval', data, encode: {...} })`(V4 链式 API 见 Forbidden Patterns)
3. **`chart.options()` 只能调用一次**:多次调用会完整覆盖前一次配置,只有最后一次生效。多 mark 叠加必须用 `type: 'view'` + `children` 数组,而不是多次调用 `chart.options()`
4. **`encode` object**: `encode: { x, y }`(禁止 V4 的 `.position('x*y')`)
5. **`transform` must be array**: `transform: [{ type: 'stackY' }]`
6. **`labels` is plural**: Use `labels: [{ text: 'field' }]` not `label: {}`
7. **`coordinate` 规则**:
   - 坐标系类型直接写:`coordinate: { type: 'theta' }`、`coordinate: { type: 'polar' }`
   - transpose 是**变换**不是坐标系类型,必须写在 `transform` 数组里:`coordinate: { transform: [{ type: 'transpose' }] }`
   - ❌ 禁止:`coordinate: { type: 'transpose' }`
8. **范围编码**(甘特图、candlestick 等):`encode: { y: 'start', y1: 'end' }`,禁止 `y: ['start', 'end']`
9. **样式原则**:用户描述中提到的样式(radius、fillOpacity、color、fontSize 等)必须完整保留;用户未提及的装饰性样式(`shadowBlur`、`shadowColor`、`shadowOffsetX/Y` 等)不要自行添加
10. **`animate` 规则**:用户未明确要求动画时不要添加 `animate` 配置(G2 自带默认动画),只有用户明确描述动画需求时才添加
11. **`scale.color.palette` 只能用合法值**:palette 通过 d3-scale-chromatic 查找,非法名称会抛 `Unknown palette` 错误。**不要推断或创造不存在的名称**(如 `'blueOrange'`、`'redGreen'`、`'hot'`、`'jet'`、`'coolwarm'` 等均非法)。合法的常用值:顺序色阶 `'blues'|'greens'|'reds'|'ylOrRd'|'viridis'|'plasma'|'turbo'`;发散色阶 `'rdBu'|'rdYlGn'|'spectral'`;不确定时用 `range: ['#startColor', '#endColor']` 自定义替代
12. **禁止在用户代码中使用 `d3.*`**:G2 内部使用 d3,但 `d3` 对象不会暴露到用户代码作用域,调用 `d3.sum()` 等会抛 `ReferenceError: d3 is not defined`。如需聚合,优先使用 G2 内置选项(如 `sortX` 的 `reducer: 'sum'`),不得不自定义时用原生 JS:`d3.sum(arr, d=>d.v)` → `arr.reduce((s,d)=>s+d.v,0)`;`d3.max(arr, d=>d.v)` → `Math.max(...arr.map(d=>d.v))`
13. **用户未指定配色时,禁止使用白色或近白色作为图形填充色**:`style: { fill: '#fff' }`、`style: { fill: 'white' }`、`style: { fill: '#ffffff' }` 等在白色背景下会让图形完全不可见。未指定配色时应依赖 G2 的 `encode.color` 自动分配主题色,或使用有明确视觉区分度的颜色(如 `'#5B8FF9'`)。以下是合法例外:label 文字 `fill: '#fff'`(深色背景内标签)、分隔线 `stroke: '#fff'`(堆叠/pack/treemap 的分隔白线)
14. **`padding` 只接受 `number | 'auto'`,禁止数组形式**:`padding: [40, 30, 40, 50]` 在 G2 v5 中无效(会被忽略或报错)。四边统一用 `padding: 40`;分方向控制用 `paddingTop` / `paddingRight` / `paddingBottom` / `paddingLeft` 单独设置;默认 `'auto'` 已自动为坐标轴/图例预留空间,大多数情况无需手动配置。**禁止设置 `padding: 0`**——会关闭自动计算,导致坐标轴/图例被截断;只需调整某一方向时单独设置对应方向即可
15. **`autoFit: true` 时禁止同时设置 `width`**:`autoFit` 会完全忽略 `width`,同时出现时 `width` 无效。`autoFit: true` 时只设 `height`;需要固定宽高时去掉 `autoFit` 改用 `width` + `height`
16. **用户未指定容器时**: `container` 默认为 `'container'`,不要通过 `document.createElement('div')` 进行创建,代码末尾必须有 `chart.render();`

### 1.1 Forbidden Patterns / 禁

_meta.json

{
  "ownerId": "kn7dnfrfapgxsqxdzvy0r1qngs8422br",
  "slug": "g2-chart",
  "version": "1.0.1",
  "publishedAt": 1777454622341
}

references/animations/g2-animation-intro.md

---
id: "g2-animation-intro"
title: "G2 动画系统总览(animate 配置)"
description: |
  G2 v5 动画系统通过 animate 属性配置,支持入场(enter)、更新(update)、退场(exit)三种时机。
  内置动画类型包括 fadeIn/Out、scaleInX/Y、growInX/Y、waveIn、zoomIn/Out、morphing、pathIn。
  每种动画可配置 duration(时长)、delay(延迟)、easing(缓动函数)。

library: "g2"
version: "5.x"
category: "animations"
tags:
  - "animation"
  - "动画"
  - "animate"
  - "入场动画"
  - "fadeIn"
  - "scaleInX"
  - "waveIn"

related:
  - "g2-animation-keyframe"
  - "g2-core-chart-init"

use_cases:
  - "图表首次渲染时添加入场动画提升视觉体验"
  - "数据更新时添加过渡动画"
  - "退场时添加淡出效果"

difficulty: "beginner"
completeness: "full"
created: "2025-03-24"
updated: "2025-03-24"
author: "antv-team"
source_url: "https://g2.antv.antgroup.com/manual/core/animate"
---

## 内置动画类型速查

| 动画名 | 效果 | 适合场景 |
|--------|------|---------|
| `fadeIn` | 从透明到不透明 | 通用入场 |
| `fadeOut` | 从不透明到透明 | 通用退场 |
| `scaleInX` | 从 X 轴起点缩放展开 | 柱状图入场 |
| `scaleInY` | 从 Y 轴底部缩放展开 | 柱状图入场(竖向) |
| `scaleOutX` | 向 X 轴收缩消失 | 柱状图退场 |
| `scaleOutY` | 向 Y 轴收缩消失 | 柱状图退场 |
| `growInX` | 从左向右生长 | 条形图、折线图入场 |
| `growInY` | 从下向上生长 | 柱状图入场 |
| `waveIn` | 波浪扫描入场 | 极坐标图(玫瑰图、饼图) |
| `zoomIn` | 从中心缩放放大 | 点图入场 |
| `zoomOut` | 向中心缩小消失 | 点图退场 |
| `pathIn` | 路径逐步绘制 | 折线图、路径图 |
| `morphing` | 形状变形过渡 | 图表类型切换 |

## 最小可运行示例

```javascript
import { Chart } from '@antv/g2';

const chart = new Chart({ container: 'container', width: 640, height: 480 });

chart.options({
  type: 'interval',
  data: [
    { genre: 'Sports', sold: 275 },
    { genre: 'Strategy', sold: 115 },
    { genre: 'Action', sold: 120 },
    { genre: 'RPG', sold: 98 },
  ],
  encode: { x: 'genre', y: 'sold', color: 'genre' },
  animate: {
    enter: {
      type: 'growInY',    // 入场动画:从下向上生长
      duration: 800,      // 持续时间(毫秒)
      delay: 0,           // 延迟
      easing: 'ease-out', // 缓动函数
    },
  },
});

chart.render();
```

## 配置动画的三个时机

```javascript
chart.options({
  type: 'interval',
  data,
  encode: { x: 'x', y: 'y', color: 'type' },
  animate: {
    // 入场:图表首次渲染时
    enter: {
      type: 'scaleInY',
      duration: 1000,
      easing: 'ease-out-bounce',
    },
    // 更新:数据变化时
    update: {
      type: 'morphing',
      duration: 500,
    },
    // 退场:图元被移除时
    exit: {
      type: 'fadeOut',
      duration: 300,
    },
  },
});
```

## 禁用动画

```javascript
// 禁用所有动画
chart.options({
  animate: false,
});

// 仅禁用入场动画
chart.options({
  animate: {
    enter: false,
  },
});
```

## 常见动画组合推荐

```javascript
// 柱状图:growInY 入场
animate: { enter: { type: 'growInY', duration: 800 } }

// 折线图:pathIn 入场(路径绘制效果)
animate: { enter: { type: 'pathIn', duration: 1200 } }

// 饼图(极坐标):waveIn 入场
animate: { enter: { type: 'waveIn', duration: 1000 } }

// 散点图:zoomIn 入场
animate: { enter: { type: 'zoomIn', duration: 600 } }

// 通用淡入
animate: { enter: { type: 'fadeIn', duration: 500 } }
```

## 常见错误与修正

### 错误 1:animate.enter 写成字符串
```javascript
// ❌ 错误:enter 不是字符串,是对象
chart.options({
  animate: { enter: 'fadeIn' },  // ❌
});

// ✅ 正确
chart.options({
  animate: { enter: { type: 'fadeIn', duration: 6

references/animations/g2-animation-keyframe.md

---
id: "g2-animation-keyframe"
title: "G2 关键帧动画(timingKeyframe)"
description: |
  timingKeyframe 是 G2 v5 的组合类型,将多个图表视图按时序播放,
  实现数据故事讲述(data storytelling)效果。
  每个子视图是一个"关键帧",系统自动在帧间插值过渡,支持形变动画(morphing)。

library: "g2"
version: "5.x"
category: "animations"
tags:
  - "timingKeyframe"
  - "关键帧"
  - "数据故事"
  - "keyframe"
  - "morphing"
  - "动画"
  - "composition"

related:
  - "g2-animation-intro"
  - "g2-core-view-composition"

use_cases:
  - "演示数据如何从一种图表类型变为另一种(柱状图 → 折线图)"
  - "展示数据随时间的演变过程"
  - "数据新闻和可视化故事讲述"

difficulty: "advanced"
completeness: "full"
created: "2025-03-24"
updated: "2025-03-24"
author: "antv-team"
source_url: "https://g2.antv.antgroup.com/manual/core/composition/timing-keyframe"
---

## 最小可运行示例(柱状图 → 折线图)

```javascript
import { Chart } from '@antv/g2';

const data = [
  { month: 'Jan', value: 83 },
  { month: 'Feb', value: 60 },
  { month: 'Mar', value: 95 },
  { month: 'Apr', value: 72 },
  { month: 'May', value: 110 },
];

const chart = new Chart({ container: 'container', width: 640, height: 480 });

chart.options({
  type: 'timingKeyframe',   // 关键帧组合类型
  duration: 1000,           // 每帧过渡时长(毫秒)
  iterationCount: 2,        // 循环次数('infinite' 为无限循环)
  direction: 'alternate',   // 'normal' | 'reverse' | 'alternate' | 'reverse-alternate'
  easing: 'ease-in-out-sine',
  children: [
    // 关键帧 1:柱状图
    {
      type: 'interval',
      data,
      encode: { x: 'month', y: 'value', color: 'month' },
      axis: { y: { title: '月份销量' } },
    },
    // 关键帧 2:折线图(自动在两者之间插值动画)
    {
      type: 'line',
      data,
      encode: { x: 'month', y: 'value' },
      style: { lineWidth: 3 },
    },
  ],
});

chart.render();
```

## 多关键帧(数据更新动画)

```javascript
chart.options({
  type: 'timingKeyframe',
  duration: 800,
  iterationCount: 'infinite',
  direction: 'alternate',
  children: [
    // 关键帧 1:2022 年数据
    {
      type: 'interval',
       data2022,
      encode: { x: 'city', y: 'gdp', color: 'city' },
      title: '2022 年 GDP',
    },
    // 关键帧 2:2023 年数据(相同字段,自动形变过渡)
    {
      type: 'interval',
      data: data2023,
      encode: { x: 'city', y: 'gdp', color: 'city' },
      title: '2023 年 GDP',
    },
  ],
});
```

## 配置项

```javascript
chart.options({
  type: 'timingKeyframe',
  duration: 1000,                  // 关键帧间过渡时长(毫秒),默认 1000
  iterationCount: 1,               // 循环次数,默认 1;'infinite' 无限循环
  direction: 'normal',             // 播放方向:
                                   //   'normal' - 正向
                                   //   'reverse' - 反向
                                   //   'alternate' - 正反交替
                                   //   'reverse-alternate' - 反正交替
  easing: 'ease-in-out-sine',     // 缓动函数,默认 'ease-in-out-sine'
  children: [/* 各关键帧视图配置 */],
});
```

## 常见错误与修正

### 错误 1:children 帧的 encode 字段名不一致——无法形变
```javascript
// ❌ 字段名不一致,无法识别对应关系,形变效果丢失
children: [
  { type: 'interval', encode: { x: 'month', y: 'sales' } },   // sales
  { type: 'line',     encode: { x: 'month', y: 'revenue' } }, // revenue ❌ 名字不同
]

//

references/animations/g2-animation-types.md

---
id: "g2-animation-types"
title: "G2 内置动画类型详解(fadeIn/scaleIn/growIn/pathIn/waveIn/zoomIn/morphing)"
description: |
  G2 v5 内置多种动画类型,每种适用于不同的 Mark 和坐标系:
  fadeIn/Out(渐显渐隐)、scaleInX/Y(缩放展开)、growInX/Y(生长入场)、
  pathIn(路径绘制)、waveIn(极坐标波浪入场)、zoomIn/Out(缩放点入场)、morphing(形变过渡)。
  通过 animate.enter.type 等配置使用。

library: "g2"
version: "5.x"
category: "animations"
tags:
  - "fadeIn"
  - "scaleInX"
  - "scaleInY"
  - "growInX"
  - "growInY"
  - "pathIn"
  - "waveIn"
  - "zoomIn"
  - "zoomOut"
  - "morphing"
  - "动画类型"

related:
  - "g2-animation-intro"
  - "g2-animation-keyframe"

use_cases:
  - "按图表类型选择最合适的入场动画"
  - "折线图路径绘制动画"
  - "饼图/玫瑰图波浪入场"
  - "数据更新时的形变过渡"

difficulty: "beginner"
completeness: "full"
created: "2025-03-24"
updated: "2025-03-24"
author: "antv-team"
source_url: "https://g2.antv.antgroup.com/manual/core/animate"
---

## 动画类型与适用场景

| 动画名 | 方向 | 最适合 Mark | 特点 |
|--------|------|------------|------|
| `fadeIn` | - | 所有 Mark | 渐显,通用,最安全 |
| `fadeOut` | - | 所有 Mark | 渐隐,退场通用 |
| `scaleInX` | X 轴 | interval(柱状图) | 从左上角向右扩展 |
| `scaleInY` | Y 轴 | interval(柱状图) | 从底部向上缩放 |
| `scaleOutX` | X 轴 | interval | scaleInX 的退场版本 |
| `scaleOutY` | Y 轴 | interval | scaleInY 的退场版本 |
| `growInX` | X 轴 | line, area, interval(直角坐标) | 裁剪从左向右生长 |
| `growInY` | Y 轴 | interval, area(直角坐标) | 裁剪从底部向上生长;**极坐标/helix 禁用** |
| `pathIn` | 路径 | line, path, link | 路径线条逐步绘制 |
| `waveIn` | 波浪 | interval(极坐标) | 极坐标专用扇形展开 |
| `zoomIn` | 中心 | point, text | 从中心缩放放大 |
| `zoomOut` | 中心 | point, text | 向中心缩小消失 |
| `morphing` | 形变 | 所有 Mark | 形状平滑变形过渡 |

## fadeIn / fadeOut(渐显渐隐)

```javascript
// 最通用的动画,适合任何 mark
chart.options({
  type: 'point',
  data,
  encode: { x: 'x', y: 'y' },
  animate: {
    enter: { type: 'fadeIn', duration: 600 },
    exit: { type: 'fadeOut', duration: 300 },
  },
});
```

## scaleInY / growInY(柱状图入场)

```javascript
// scaleInY:缩放展开(有缩放感)
// growInY:裁剪生长(有"从地面长出来"的感觉,更自然)
chart.options({
  type: 'interval',
  data,
  encode: { x: 'genre', y: 'sold' },
  animate: {
    // 方式一:缩放
    enter: { type: 'scaleInY', duration: 800, easing: 'ease-out' },
    // 方式二:生长(推荐)
    // enter: { type: 'growInY', duration: 800 },
  },
});
```

## pathIn(折线图路径绘制)

```javascript
// pathIn:折线/路径从左向右逐步绘制
chart.options({
  type: 'line',
  data: timeSeriesData,
  encode: { x: 'date', y: 'value', color: 'type' },
  animate: {
    enter: {
      type: 'pathIn',      // 路径逐步绘制
      duration: 1500,
      easing: 'linear',    // 匀速绘制效果更佳
    },
  },
});
```

## waveIn(极坐标/饼图专用)

```javascript
// waveIn:从外圈向内的波浪扫入,专为极坐标设计
chart.options({
  type: 'interval',
  data,
  encode: { y: 'value', color: 'type' },
  transform: [{ type: 'stackY' }],
  coordinate: { type: 'theta', outerRadius: 0.8 },
  animate: {
    enter: {
      type: 'waveIn',       // 极坐标专用
      duration: 1000,
    },
  },
});
```

## zoomIn / zoomOut(点图缩放)

```javascript
// zoomIn:散点从中心缩放出现
chart.options({
  type: 'point',
  data: scatterData,
  encode: { x: 'x', y: 'y', size: 'value' },
  animate: {
    enter: { type: 'zo

Sponsored

Ads related to AntV Skills and adjacent AI workflows.