UNPKG

5.24 kBMarkdownView Raw
1<img src="https://gw.alipayobjects.com/zos/antfincdn/R8sN%24GNdh6/language.svg" width="18"> English | [简体中文](./README.md)
2
3<h1 align="center">
4<b>G2</b>
5</h1>
6
7<div align="center">
8
9A highly interactive data-driven visualization grammar for statistical charts.
10
11[![](https://img.shields.io/travis/antvis/g2.svg)](https://travis-ci.org/antvis/g2) ![CI](https://github.com/antvis/G2/workflows/CI/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/antvis/G2/badge.svg?branch=master)](https://coveralls.io/github/antvis/G2?branch=master) [![NPM Package](https://img.shields.io/npm/v/@antv/g2.svg)](https://www.npmjs.com/package/@antv/g2) [![NPM Downloads](http://img.shields.io/npm/dm/@antv/g2.svg)](https://npmjs.org/package/@antv/g2) ![Dependencies](https://img.shields.io/badge/dependencies-up%20to%20date-brightgreen.svg) [![Percentage of issues still open](http://isitmaintained.com/badge/open/antvis/g2.svg)](http://isitmaintained.com/project/antvis/g2 'Percentage of issues still open') [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=shields)](https://github.com/antvis/g2/pulls)
12
13![](https://img.shields.io/badge/language-TypeScript-red.svg) ![](https://img.shields.io/badge/license-MIT-000000.svg)
14
15[![](https://img.shields.io/twitter/follow/AntV_Alipay.svg?label=AntV&style=social)](https://twitter.com/AntV_Alipay)
16
17</div>
18
19<p align="center">
20 <a href="https://g2.antv.vision/en">Website</a>
21 <a href="https://g2.antv.vision/en/docs/manual/about-g2">Tutorial Docs</a>
22 <a href="https://www.yuque.com/antv">Blog</a>
23 <a href="https://github.com/antvis/G2Plot">G2Plot</a>
24</p>
25
26G2 is a visualization grammar, a data-driven visual language with a high level of usability and scalability. It provides a set of grammars, takes users beyond a limited set of charts to an almost unlimited world of graphical forms. With G2, you can describe the visual appearance and interactive behavior of a visualization just by one statement, and generate web-based views using Canvas or SVG.
27
28## 📺 Live Demos
29
30<a href="https://g2.antv.vision/en/examples/gallery"><img src="https://user-images.githubusercontent.com/6628666/75466330-fe1d0c00-59c4-11ea-91ba-506f60ef8af4.png" style='width: 100%'/></a>
31
32## ✨ Features
33
34- 💯Stable grammar of graphics: enable to draw all kinds of charts by mapping data to graphics.
35- 🤩New grammar of interaction: interaction behaviors combined with Trigger and Action mechanisms are used to exploring data.
36- 🦍Advanced View module: with the ability to develop customized multi-dimension data analysis graphics.
37- 👬Dual-engine rendering: with the ability to switch Canvas and SVG freely.
38- 💄Visual components: interaction-oriented, elegant experience.
39- 🛡Fully embrace TypeScript: Complete type definition files are provided.
40
41## 📦 Installation
42
43```bash
44$ npm install @antv/g2
45```
46
47## 🔨 Getting Started
48
49<img src="https://gw.alipayobjects.com/mdn/rms_2274c3/afts/img/A*8qbLQb7A0loAAAAAAAAAAABkARQnAQ" style="width: 600px">
50
51Before drawing we need to prepare a DOM container for G2:
52
53```html
54<div id="c1"></div>
55```
56
57```ts
58import { Chart } from '@antv/g2';
59
60const data = [
61 { genre: 'Sports', sold: 275 },
62 { genre: 'Strategy', sold: 115 },
63 { genre: 'Action', sold: 120 },
64 { genre: 'Shooter', sold: 350 },
65 { genre: 'Other', sold: 150 },
66];
67
68// Step 1: Create a Chart instance.
69const chart = new Chart({
70 container: 'c1', // Specify chart container ID
71 width: 600, // Specify chart width
72 height: 300, // Specify chart height
73});
74
75// Step 2: Load the data.
76chart.data(data);
77
78// Step 3: Declare the grammar of graphics, draw column chart.
79chart.interval().position('genre*sold');
80
81// Step 4: Render chart.
82chart.render();
83```
84
85## ⌨️ Development
86
87```bash
88# Install dependencies
89$ npm install
90
91# Run test cases
92$ npm run test
93
94# Open electron to run test cases and listen to file changes
95$ npm run test-live
96
97# Run CI
98$ npm run ci
99
100# Run website
101$ npm start
102```
103
104## 🏷️ Releases
105
106- v3.5.x: https://github.com/antvis/G2/tree/v3.5.x
107- v4.0.x: https://github.com/antvis/G2/tree/v4.0.x
108
109> You can also use **[G2Plot](https://github.com/antvis/G2Plot)** which is an interactive and responsive charting library based on G2. You can easily make superior statistical plots through a few lines of code.
110
111## 🤝 How to Contribute
112
113Please let us know how can we help. Do check out [issues](https://github.com/antvis/g2/issues) for bug reports or suggestions first.
114
115To become a contributor, please follow our [contributing guide](https://github.com/antvis/g2/blob/master/CONTRIBUTING.md).
116
117<a href="https://issuehunt.io/r/antvis/G2" rel="nofollow" target="_blank"><img src="https://camo.githubusercontent.com/fcf6ed4dcbd95ccadfe62647fc93194b7262c862de38406e5dae68aa682c85c3/68747470733a2f2f697373756568756e742e696f2f7374617469632f656d6265642f697373756568756e742d627574746f6e2d76312e737667" alt="Let's fund issues in this repository" data-canonical-src="https://issuehunt.io/static/embed/issuehunt-button-v1.svg" style="max-width:100%;"></a>
118
119## 📧 Contact us
120
121DingTalk Group: 30233731 / 35686967 (2 群)
122
123<img src="https://gw.alipayobjects.com/zos/antfincdn/8qEHi7GiaN/G2Plot-dingding.JPG" width="200" height="266" />