antvis/G2



The issue has been closed
v5 性能问题:1w+ 数据出现较长时间卡顿,cpu占有率一度达到100%,具体实现如下 #4846
tiehongji posted onGitHub
<!-- Thank you for your pull request. Please review below requirements. Bug fixes and new features should include tests and possibly benchmarks. Contributors guide: https://github.com/antvis/g2/blob/master/CONTRIBUTING.md 感谢您贡献代码。请确认下列 checklist 的完成情况。 Bug 修复和新功能必须包含测试,必要时请附上性能测试。 Contributors guide: https://github.com/antvis/g2/blob/master/CONTRIBUTING.md -->
import React, { useCallback, useEffect, useRef } from 'react';
import { useChartData } from './hooks';
import dayjs from 'dayjs';
import { Chart } from '@antv/g2';
const Home = () => {
const chartDom = useRef(null);
const chart = useRef(null);
const [data, getData] = useChartData(10000);
const initChart = useCallback(() => {
if (chart?.current) {
chart.current.changeData(data);
} else {
chart.current = new Chart({
container: 'main',
theme: 'classic',
});
chart.current
.line() // 创建一个 Interval 标记
.data(data) // 绑定数据
.encode('x', 'xField') // 编码 x 通道
.encode('y', 'value'); // 编码 y 通道
chart.current
.point() // 创建一个 Interval 标记
.data(data) // 绑定数据
.encode('x', 'xField') // 编码 x 通道
.encode('y', 'value');
// 渲染可视化
chart.current.render();
}
}, [data]);
useEffect(() => {
initChart();
}, [initChart]);
return (
<div>
<div ref={chartDom} id="main" style={{ height: 500, width: '100%' }}></div>
</div>
);
};
export default Home;
Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->
-
npm test
passes - benchmarks are included
- commit message follows commit guidelines
- documents are updated
Description of change
<!-- Provide a description of the change below this comment. -->