|
1 | 1 | # @berryv/g2-react
|
2 | 2 |
|
3 |
| -> WIP |
4 |
| -
|
5 |
| -The lightweight [React](https://react.dev/) component for [@antv/g2 5.0](https://github.com/antvis/G2). |
| 3 | +The lightweight [React](https://react.dev/) component for [@antv/g2 5.0](https://github.com/antvis/G2), which is based on the [Spec API](https://g2.antv.antgroup.com/manual/core/api). |
6 | 4 |
|
7 | 5 | ## Installing
|
8 | 6 |
|
@@ -40,21 +38,23 @@ export function Demo() {
|
40 | 38 | | Property | Description | Type | Default |
|
41 | 39 | | -------- | --------------------------------------------------------------------------------------------------------------- | --------------------- | ------- |
|
42 | 40 | | options | the [options](https://g2.antv.antgroup.com/manual/core/api) for the visualization, say `chart.options(options)` | `G2options` \| `null` | - |
|
43 |
| -| renderer | the [renderer](https://g.antv.antgroup.com/api/renderer/intro) of @antv/g canvas. | `ChartOptions` | - | |
| 41 | +| renderer | the [renderer](https://g.antv.antgroup.com/api/renderer/intro) of @antv/g canvas | `ChartOptions` | - | |
44 | 42 | | style | the style of the container | `CSSProperties` | - |
|
45 | 43 | | onInit | the callback called after the chart instantiating | `Function` | - |
|
46 | 44 | | ref | the ref for the [chart instance](https://g2.antv.antgroup.com/manual/core/chart) | `ChartRef` | - |
|
47 | 45 |
|
48 | 46 | ## Examples
|
49 | 47 |
|
50 | 48 | - [Creating Chart](#creating-chart)
|
51 |
| -- [Fetching Data](#fetching-data) |
| 49 | +- [Fetching Data](#updating-data) |
52 | 50 | - [Handling Events](#handling-events)
|
53 | 51 | - [Customizing Component](#customizing-component)
|
54 | 52 | - [Styling Container](#styling-container)
|
55 | 53 |
|
56 | 54 | ## Creating Chart
|
57 | 55 |
|
| 56 | +For more examples for `props.options`, see each [G2 example](https://g2.antv.antgroup.com/examples) and click the "Spec Tab". |
| 57 | + |
58 | 58 | ```js
|
59 | 59 | import React from "react";
|
60 | 60 | import { Chart } from "@berryv/g2-react";
|
@@ -83,7 +83,9 @@ export function Demo() {
|
83 | 83 | }
|
84 | 84 | ```
|
85 | 85 |
|
86 |
| -### Fetching Data |
| 86 | +### Updating Data |
| 87 | + |
| 88 | +Using `useMemo` to define a computed options with data as a decency, this allows rerendering chart after the data updating. |
87 | 89 |
|
88 | 90 | ```js
|
89 | 91 | import React, { useState, useMemo } from "react";
|
@@ -122,6 +124,8 @@ export function Demo() {
|
122 | 124 |
|
123 | 125 | ### Handling Events
|
124 | 126 |
|
| 127 | +`<Chart/>` exposes the ref for the G2 [chart instance](https://g2.antv.antgroup.com/manual/core/chart), which can be used to handle events or get some instances, such as scale, coordinate, etc,. |
| 128 | + |
125 | 129 | ```js
|
126 | 130 | import React, { useRef, useEffect } from "react";
|
127 | 131 | import { ChartEvent } from "@antv/g2";
|
@@ -153,6 +157,8 @@ export function Demo() {
|
153 | 157 |
|
154 | 158 | ### Customizing Component
|
155 | 159 |
|
| 160 | +With the `register` API of G2, you can customize visual component and using it in options, such as customizing a triangle shape for bar chart: |
| 161 | + |
156 | 162 | ```js
|
157 | 163 | import React, { useRef, useEffect } from "react";
|
158 | 164 | import { register } from "@antv/g2";
|
@@ -203,6 +209,8 @@ export function Demo() {
|
203 | 209 |
|
204 | 210 | ### Styling Container
|
205 | 211 |
|
| 212 | +Define the css styles of the container: |
| 213 | + |
206 | 214 | ```js
|
207 | 215 | import React from "react";
|
208 | 216 | import { Chart } from "@berryv/g2-react";
|
|
0 commit comments