Skip to content

antvis/G2

v5
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
February 15, 2022 15:06
src
March 17, 2023 20:57
March 21, 2022 16:52
March 16, 2023 14:06

English | 简体中文

G2 5.0

简�?的�?进�?�?�视化语法

介�? • 案例 • 教程 • API

Build Status Coverage Status npm Version npm Download npm License

examples

G2 5.0 �?�布了 Beta 版本,4.x 稳定版在 master 分支上。

G2 起�?于 Wilkinson 的图形语法:《Grammar of Graphics》,但�?��?止于图形语法。

✨ 特色

  • �?进�?语法:结�?�工业和学术实践,实现图形语法�?动画语法和交互语法。
  • 丰富的标记:内置 10+ 基础标记,8+ 高阶标记。
  • 高�?�扩展性:�??供统一机制扩展所有�?�视化组件。
  • 个性化风格:支�?手绘�?圆角�?纹�?�等风格。
  • 多环境渲染:支�? Canvas�?SVG 以�?� WebGL,和 Node.js �?务端渲染。

🔨 开始使用

�?�以通过 NPM 或 Yarn 等包管�?�器�?�安装。

$ npm install @antv/g2@rc
$ yarn add @antv/g2@rc

�?功安装之�?�,�?�以通过 import 导入 Chart 对象。

<div id="container"></div>
import { Chart } from '@antv/g2';

// 准备数�?�
const data = [
  { genre: 'Sports', sold: 275 },
  { genre: 'Strategy', sold: 115 },
  { genre: 'Action', sold: 120 },
  { genre: 'Shooter', sold: 350 },
  { genre: 'Other', sold: 150 },
];

// �?始化图表实例
const chart = new Chart({
  container: 'container',
  theme: 'classic',
});

// 声明�?�视化
chart
  .interval() // 创建一个 Interval 标记
  .data(data) // 绑定数�?�
  .encode('x', 'genre') // 编�? x 通�?�
  .encode('y', 'sold'); // 编�? y 通�?�

// 渲染�?�视化
chart.render();

如果一切顺利,你�?�以得到下�?�的柱状图!

📮 �?�与贡献

  • 问题: 报告 bug 或者�??出需求
  • 贡献指�?�:�?�与建设 G2
  • 讨论:在 Github 上或者钉钉群里�?�讨论(30233731, 35686967, 44788198)

📄 许�?��?

MIT@AntV.