# @antv/antv-spec 中文文档

规范地址：https://npmcn.com/package/%40antv/antv-spec/

版本：0\.1\.0-alpha\.18
npm 元数据更新时间：2026-09-21T08:44:37.213Z
中文译文更新时间：2026-11-06T07:14:58.716Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40antv/antv-spec
原文对照：https://npmcn.com/package/%40antv/antv-spec/?lang=original
项目主页：https://github.com/antvis/antv-spec#readme
源码仓库：https://github.com/antvis/antv-spec

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：277 kB，245 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- peer 依赖：@antv/g6 ^4\.3\.11，@antv/g2plot ^2\.3\.27
- 首次发布：2021-08-25T05:51:53.996Z
- 最新版本发布：2021-11-19T08:49:08.908Z
- 近 30 天下载量：10475（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：17（近 12 个月 0 个）

## 中文简介

一种支持各种技术堆积AntV的宣说语法.

## 安装

```sh
npm install @antv/antv-spec
```

也可以使用：`pnpm add @antv/antv-spec`、`yarn add @antv/antv-spec`、`bun add @antv/antv-spec`

## README

# 蚂蚁光谱

一种支持各种技术堆积AntV的宣说语法.

## 特征

**计划**: AntV 的统一可视化方案  
**适配器**: 将计划翻译为图表库

## 安装

```bash
npm install @antv/antv-spec
```

## 示例

```ts
import { useEffect } from "react";
import { AntVSpec, specToG2Plot } from "@antv/antv-spec";

export default function App() {
  const chartSpec: AntVSpec = {
    basis: {
      type: "chart"
    },
    data: {
      type: "json-array",
      values: [
        { year: "2007", sales: 28, type: "A" },
        { year: "2008", sales: 55, type: "A" },
        { year: "2009", sales: 43, type: "A" },
        { year: "2010", sales: 91, type: "A" },
        { year: "2011", sales: 81, type: "A" },
        { year: "2012", sales: 53, type: "A" },
        { year: "2013", sales: 19, type: "A" },
        { year: "2014", sales: 87, type: "A" },
        { year: "2015", sales: 52, type: "A" },

        { year: "2007", sales: 34, type: "B" },
        { year: "2008", sales: 52, type: "B" },
        { year: "2009", sales: 70, type: "B" },
        { year: "2010", sales: 11, type: "B" },
        { year: "2011", sales: 46, type: "B" },
        { year: "2012", sales: 79, type: "B" },
        { year: "2013", sales: 23, type: "B" },
        { year: "2014", sales: 54, type: "B" },
        { year: "2015", sales: 99, type: "B" }
      ]
    },
    layer: [
      {
        mark: {
          type: "line",
          style: { color: "#444444" }
        },
        encoding: {
          x: {
            field: "year",
            type: "temporal"
          },
          y: {
            field: "sales",
            type: "quantitative"
          },
          color: {
            field: "type",
            type: "nominal",
            scale: {
              range: ["#5c0011", "#ffec3d", "#7cb305", "#08979c", "#003a8c"]
            }
          }
        }
      }
    ]
  };

  useEffect(() => {
    specToG2Plot(chartSpec, document.getElementById("container"));
  });

  return <div className="container"></div>;
}

```

## 文档

这个计划仍然是alpha版本. 我们热烈欢迎任何贡献.

更多用法请检查 [快速 API](https://npmcn.com/package/%40antv/antv-spec/API.md)。 。 。 .

## 常见问题

### @antv/antv-spec 是什么？

一种支持各种技术堆积AntV的宣说语法\.

### 如何安装 @antv/antv-spec？

在项目目录运行 npm install @antv/antv-spec，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@antv/g6（^4\.3\.11）、@antv/g2plot（^2\.3\.27）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @antv/antv-spec 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @antv/antv-spec 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @antv/antv-spec 可以商用吗？

@antv/antv-spec 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @antv/antv-spec 的下载量有多少？

根据 npm 官方下载统计，@antv/antv-spec 在 2026/10/06 – 2026/11/04 这 30 天内被下载 10,475 次，日均约 349 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @antv/antv-spec 还在维护吗？

最新版本 0\.1\.0-alpha\.18 发布于 2021/11/19（4 年前）；至今共发布 17 个版本，其中过去 12 个月发布了 0 个；首次发布于 2021/08/25。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

