
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
@ant-design/charts-yfd
Advanced tools
A React chart library, based on G2Plot
$ npm install @ant-design/charts
import React, { Component, createRef } from 'react';
import { Line } from '@ant-design/charts';
class Page extends Component {
ref = createRef();
// DownloadImage
downloadImage = () => {
this.ref.current?.downloadImage();
};
// Get data base64
toDataURL = () => {
console.log(this.ref.current?.toDataURL());
};
render() {
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,
title: {
visible: true,
text: '带数据点的折线图',
},
xField: 'year',
yField: 'value',
};
return (
<div>
<button type="button" onClick={this.downloadImage} style={{ marginRight: 24 }}>
下载图片
</button>
<button type="button" onClick={this.toDataURL}>
获取图片信息
</button>
<Line {...config} chartRef={this.ref} />
</div>
);
}
}
export default Page;
import React, { useRef } from 'react';
import { Line } from '@ant-design/charts';
const Page: 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,
title: {
visible: true,
text: '带数据点的折线图',
},
xField: 'year',
yField: 'value',
};
const ref = useRef();
// 导出图片
const downloadImage = () => {
ref.current?.downloadImage();
};
// 获取图表 base64 数据
const toDataURL = () => {
console.log(ref.current?.toDataURL());
};
return (
<div>
<button type="button" onClick={downloadImage} style={{ marginRight: 24 }}>
导出图片
</button>
<button type="button" onClick={toDataURL}>
获取图表信息
</button>
<Line {...config} chartRef={ref} />
</div>
);
};
export default Page;
result:
Direct G2Plot
Extra props:
Property | Description | Type | defaultValue |
---|---|---|---|
chartRef | chart ref | (React.MutableRefObject<Line>)=> void | - |
className | container class | string | - |
style | container style | React.CSSProperties | - |
memoData | controll rerender | string | number | any [] | - |
We welcome all contributions.
Charts is available under the License MIT.
# 安装依赖
$ npm install
# 开发 library
$ npm run dev
FAQs
React translate g2plot
We found that @ant-design/charts-yfd demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 22 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.