$ npm install @ant-design/charts
A React chart library, based on g2plot
$ npm install @ant-design/charts
import React, { useRef } from 'react';
import { Line } from '@ant-design/charts';
const App: React.FC = () => {
const data = [
{ year: '1991', value: 3 },
{ year: '1992', value: 4 },
{ year: '1993', value: 3.5 },
{ year: '1994', value: 5 },
{ year: '1995', value: 4.9 },
{ year: '1996', value: 6 },
{ year: '1997', value: 7 },
{ year: '1998', value: 9 },
{ year: '1999', value: 13 },
];
const config = {
data,
xField: 'year',
yField: 'value',
title: {
visible: true,
text: '我是标题',
},
};
const ref = useRef(null);
return <Line chartRef={ref} {...config} />;
};
export default App;
import React, { useState, useEffect } from 'react';
import { Bubble } from '@ant-design/charts';
const App: React.FC = () => {
const [data, setData] = useState([]);
useEffect(() => {
asyncFetch();
}, []);
const asyncFetch = () => {
fetch('https://gw.alipayobjects.com/os/basement_prod/86530df2-6d61-4485-b645-0f2c5d59c07e.json')
.then((response) => response.json())
.then((json) => setData(json))
.catch((error) => {
console.log('fetch data failed', error);
});
};
const config = {
data,
title: {
visible: true,
text: '基础气泡图',
},
xField: 'change in female rate',
yField: 'change in male rate',
sizeField: 'pop',
pointSize: [4, 30],
colorField: 'continent',
color: ['#ffd500', '#82cab2', '#193442', '#d18768', '#7e827a'],
pointStyle: {
stroke: '#777777',
lineWidth: 1,
opacity: 0.8,
},
xAxis: {
visble: true,
max: 5,
min: -25,
},
};
return <Bubble {...config} />;
};
export default App;
Direct G2Plot
Extra props:
| Property | Description | Type | defaultValue |
|---|---|---|---|
| chartRef | chart ref | (React.MutableRefObject<Line>)=> void | - |
| className | container class | string | - |
| style | container style | React.CSSProperties | - |
We welcome all contributions.
Charts is available under the License MIT.
# 安装依赖
$ npm install
# 开发 library
$ npm run dev
Ordered by date of first contribution.
© 2010 - cnpmjs.org x YWFE | Home | YWFE