Skip to content

Commit 1f70149

Browse files
committed
chore: update readme
1 parent 569e1a3 commit 1f70149

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
11
# @fanciers/echarts-react
22

33
> Using ECharts in React the Idiomatic Way, with Treeshaking Support! 🍃
4+
5+
```shell
6+
npm install @fanciers/echarts-react
7+
```
8+
9+
```typescript
10+
import { CanvasRenderer, LineChart, echarts } from '@fanciers/echarts-react';
11+
12+
echarts.use([CanvasRenderer]);
13+
14+
function Demo() {
15+
return (
16+
<LineChart
17+
style={{ width: 480, height: 300 }}
18+
xAxis={{
19+
type: 'category',
20+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
21+
}}
22+
yAxis={{ type: 'value' }}
23+
series={[
24+
{
25+
type: 'line',
26+
data: [150, 230, 224, 218, 135, 147, 260],
27+
},
28+
]}
29+
/>
30+
);
31+
}
32+
```

src/charts.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ interface ChartBaseProps<T extends readonly ChartComponentType<any>[]> {
2929
style?: React.CSSProperties;
3030
containerProps?: React.HTMLAttributes<HTMLDivElement>;
3131
compose?: [...T];
32+
use?: EChartExt;
3233
children?: React.ReactNode;
3334
}
3435

@@ -50,15 +51,15 @@ interface ChartComponentType<T extends ComponentOption> {
5051
function defineChart<T extends ComponentOption>(ext: EChartExt) {
5152
const ChartComponent = React.forwardRef(
5253
(
53-
{ className, style, containerProps, compose, children, ...props }: ChartBaseProps<any>,
54+
{ className, style, containerProps, compose, use, children, ...props }: ChartBaseProps<any>,
5455
ref: React.ForwardedRef<echarts.ECharts>
5556
) => {
5657
const containerRef = React.useRef<HTMLDivElement>(null);
5758
const chartRef = React.useRef<echarts.ECharts | null>(null);
5859
const ctx = useInitialChartContext();
5960

6061
useRegister((echarts) => {
61-
echarts.use([ext, compose?.map((comp) => comp.ext).flat() || []].flat());
62+
echarts.use([ext, use, compose?.map((comp) => comp.ext).flat() || []].flat().filter(Boolean));
6263
});
6364

6465
React.useLayoutEffect(() => {

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { CanvasRenderer, SVGRenderer } from 'echarts/renderers';
12
export { LineChart, PieChart } from './charts.js';
23
export {
34
Dataset,

0 commit comments

Comments
 (0)