Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Sep 26, 2023
1 parent d4e2fec commit 738686b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# @berryv/g2-react

> WIP
The lightweight [React](https://react.dev/) component for [@antv/g2 5.0](https://github.com/antvis/G2).
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).

## Installing

Expand Down Expand Up @@ -40,21 +38,23 @@ export function Demo() {
| Property | Description | Type | Default |
| -------- | --------------------------------------------------------------------------------------------------------------- | --------------------- | ------- |
| options | the [options](https://g2.antv.antgroup.com/manual/core/api) for the visualization, say `chart.options(options)` | `G2options` \| `null` | - |
| renderer | the [renderer](https://g.antv.antgroup.com/api/renderer/intro) of @antv/g canvas. | `ChartOptions` | - |
| renderer | the [renderer](https://g.antv.antgroup.com/api/renderer/intro) of @antv/g canvas | `ChartOptions` | - |
| style | the style of the container | `CSSProperties` | - |
| onInit | the callback called after the chart instantiating | `Function` | - |
| ref | the ref for the [chart instance](https://g2.antv.antgroup.com/manual/core/chart) | `ChartRef` | - |

## Examples

- [Creating Chart](#creating-chart)
- [Fetching Data](#fetching-data)
- [Fetching Data](#updating-data)
- [Handling Events](#handling-events)
- [Customizing Component](#customizing-component)
- [Styling Container](#styling-container)

## Creating Chart

For more examples for `props.options`, see each [G2 example](https://g2.antv.antgroup.com/examples) and click the "Spec Tab".

```js
import React from "react";
import { Chart } from "@berryv/g2-react";
Expand Down Expand Up @@ -83,7 +83,9 @@ export function Demo() {
}
```

### Fetching Data
### Updating Data

Using `useMemo` to define a computed options with data as a decency, this allows rerendering chart after the data updating.

```js
import React, { useState, useMemo } from "react";
Expand Down Expand Up @@ -122,6 +124,8 @@ export function Demo() {

### Handling Events

`<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,.

```js
import React, { useRef, useEffect } from "react";
import { ChartEvent } from "@antv/g2";
Expand Down Expand Up @@ -153,6 +157,8 @@ export function Demo() {

### Customizing Component

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:

```js
import React, { useRef, useEffect } from "react";
import { register } from "@antv/g2";
Expand Down Expand Up @@ -203,6 +209,8 @@ export function Demo() {

### Styling Container

Define the css styles of the container:

```js
import React from "react";
import { Chart } from "@berryv/g2-react";
Expand Down

0 comments on commit 738686b

Please sign in to comment.