UNPKG

5.5 kBMarkdownView Raw
1<img src="https://gw.alipayobjects.com/zos/antfincdn/R8sN%24GNdh6/language.svg" width="18"> English | [简体中文](./README.zh-CN.md)
2
3<h1 align="center">
4<b>G2 5.0</b>
5</h1>
6
7<div align="center">
8
9G2 is a visualization grammar for dashboard building, data exploration and storytelling.
10
11[![Build Status](https://github.com/antvis/g2/workflows/build/badge.svg?branch=v5)](https://github.com/antvis//actions)
12[![Coverage Status](https://img.shields.io/coveralls/github/antvis/g2/v5.svg)](https://coveralls.io/github/antvis/g2?branch=v5)
13[![npm Version](https://img.shields.io/npm/v/@antv/g2.svg)](https://www.npmjs.com/package/@antv/g2)
14[![npm Download](https://img.shields.io/npm/dm/@antv/g2.svg)](https://www.npmjs.com/package/@antv/g2)
15[![npm License](https://img.shields.io/npm/l/@antv/g2.svg)](https://www.npmjs.com/package/@antv/g2)
16
17![examples](https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*_GfqQoRCqQkAAAAAAAAAAAAADmJ7AQ/fmt.webp)
18
19</div>
20
21G2 is named after Leland Wilkinson’s book _The Grammar of Graphics_ and was profoundly inspired by it in the very beginning. Here are some resources you can begin with:
22
23- [Introduction](https://g2.antv.antgroup.com/manual/introduction/what-is-g2) - a brief overview and G2's motivations
24- [Examples](https://g2.antv.antgroup.com/examples) - a large number of demos to learn from and copy-paste
25- [Tutorials](https://g2.antv.antgroup.com/manual/introduction/getting-started) - interactive case-driven guides of G2's core concepts
26- [API Reference](https://g2.antv.antgroup.com/api/overview) - complete documentation for all visualization components
27- [Editor](https://editor.antv.antgroup.com/) - an intelligent generation tool based on AntV. It utilizes AI to reduce the development cost of data visualization, and can quickly generate visual charts through natural language.
28
29## ✨ Features
30
31- **Progressive Usage** - The main objective of G2 is to help you get meaningful visualizations quickly with concise declarations and it infers the rest. But you can configure much more for complex and advanced situations.
32- **Declarative API** - We employs a functional declarative API to specify chart options in a programmatic fashion, which contributes to better logic reuse and more flexible code organization.
33- **High Extensibility** - To satisfy specific needs, G2 provides a convenient and consistent mechanism to extend everything you can imagine, whether a scale, a transform, a mark, etc,. You can even customize a brand new visualization tool based on this mechanism.
34- **Comprehensive Grammar** - G2 rejects a chart typology in favor of marks, transforms, scales, coordinates, and compositions. In addition to static visual representations, it's possible to declare data-driven animations and apply well-designed action-based interactions to plots as well.
35- **Powerful Renderer** - There is a powerful renderer [G](https://github.com/antvis/G) under G2 to generate web-based visualizations using Canvas, SVG or WebGL. The plenty of plugins it has benefit G2 from rendering charts with novel styles such as hand-drawn and fully embracing the ecosystem of [D3](https://github.com/d3/d3).
36
37## 🔨 Getting Started
38
39G2 is usually installed via a package manager such as npm or Yarn.
40
41```bash
42$ npm install @antv/g2
43```
44
45```bash
46$ yarn add @antv/g2
47```
48
49The Chart object then can be imported from G2.
50
51```html
52<div id="container"></div>
53```
54
55```js
56import { Chart } from '@antv/g2';
57
58// A tabular data to be visualized.
59const data = [
60 { genre: 'Sports', sold: 275 },
61 { genre: 'Strategy', sold: 115 },
62 { genre: 'Action', sold: 120 },
63 { genre: 'Shooter', sold: 350 },
64 { genre: 'Other', sold: 150 },
65];
66
67// Instantiate a new chart.
68const chart = new Chart({
69 container: 'container',
70});
71
72// Specify visualization.
73chart
74 .interval() // Create an interval mark and add it to the chart.
75 .data(data) // Bind data for this mark.
76 .encode('x', 'genre') // Assign genre column to x position channel.
77 .encode('y', 'sold') // Assign sold column to y position channel.
78 .encode('color', 'genre'); // Assign genre column to color channel.
79
80// Render visualization.
81chart.render();
82```
83
84If all goes well, you can get the following lovely bar chart!
85
86<img src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*XqCnTbkpAkQAAAAAAAAAAAAADmJ7AQ/fmt.webp" width="640" alt="example">
87
88## 🌍 Ecosystem
89
90- [g2-react](https://github.com/pearmini/g2-react) - The lightweight React component for G2, without extra features.
91- [g2-extensions](https://github.com/antvis/g2-extensions) - The one-stop shop for official G2 extensions, such as 3d visualization, automated visual analytics, etc.
92- [ant-design-charts](https://github.com/ant-design/ant-design-charts) - The React chart library, based on [G2](https://github.com/antvis/G2), [G6](https://github.com/antvis/G6), [X6](https://github.com/antvis/X6), [L7Plot](https://github.com/antvis/L7Plot).
93- [More...](https://github.com/antvis/G2/discussions/5772)
94
95## 📮 Contributing
96
97- [Issues](https://github.com/antvis/g2/issues) - report bugs or request features
98- [Contributing Guide](https://github.com/antvis/g2/blob/v5/CONTRIBUTING.md) - help build G2
99- [Discussions](https://github.com/antvis/G2/discussions) - discuss on GitHub or in DingTalk group(30233731, 35686967, 44788198)
100
101<img src="https://gw.alipayobjects.com/zos/antfincdn/hTzzaqgHgQ/Antv%252520G2%252520%26%252520G2Plot.png" width="200" height="266" alt="code"/>
102
103## 📄 License
104
105MIT@[AntV](https://github.com/antvis).