English | 简体中文
简洁的渐进式可视化语法,用于构建仪表盘、数据探索以及数据讲故事。

G2 起源于 Leland Wilkinson 的图形语法:《The Grammar of Graphics》,但又不止于图形语法。
可以通过 NPM 或 Yarn 等包管理器来安装。
$ npm install @antv/g2
$ yarn add @antv/g2
成功安装之后,可以通过 import 导入 Chart 对象。
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',
});
// 声明可视化
chart
.interval() // 创建一个 Interval 标记
.data(data) // 绑定数据
.encode('x', 'genre') // 编码 x 通道
.encode('y', 'sold') // 编码 y 通道
.encode('color', 'genre'); // 编码 color 通道
// 渲染可视化
chart.render();
如果一切顺利,你可以得到下面的柱状图!

感谢所有为这个项目做出贡献的人,感谢所有支持者!🙏

MIT@AntV.