mirror of
https://github.com/didi/KnowStreaming.git
synced 2026-01-12 02:54:59 +08:00
feat: update echarts v4 to v5
This commit is contained in:
@@ -1,25 +1,45 @@
|
||||
import React from 'react';
|
||||
import echarts, { EChartOption } from 'echarts/lib/echarts';
|
||||
import 'echarts/lib/chart/pie';
|
||||
import 'echarts/lib/chart/line';
|
||||
import 'echarts/lib/component/legend';
|
||||
import 'echarts/lib/component/tooltip';
|
||||
import 'echarts/lib/component/title';
|
||||
import 'echarts/lib/component/axis';
|
||||
import * as echarts from 'echarts/core';
|
||||
import './index.less';
|
||||
|
||||
// 引入柱状图
|
||||
import { PieChart, LineChart } from 'echarts/charts';
|
||||
|
||||
// 引入提示框和标题组件
|
||||
import {
|
||||
TitleComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
GridComponent,
|
||||
ToolboxComponent,
|
||||
DatasetComponent,
|
||||
} from 'echarts/components';
|
||||
import { CanvasRenderer } from 'echarts/renderers';
|
||||
|
||||
// 注册必须的组件
|
||||
echarts.use([
|
||||
PieChart,
|
||||
LineChart,
|
||||
ToolboxComponent,
|
||||
TitleComponent,
|
||||
LegendComponent,
|
||||
TooltipComponent,
|
||||
GridComponent,
|
||||
DatasetComponent,
|
||||
CanvasRenderer,
|
||||
]);
|
||||
export interface IEchartsProps {
|
||||
width?: number;
|
||||
height?: number;
|
||||
options?: EChartOption;
|
||||
options?: any;
|
||||
}
|
||||
|
||||
export const hasData = (options: EChartOption) => {
|
||||
export const hasData = (options: any) => {
|
||||
if (options && options.series && options.series.length) return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
export default class LineChart extends React.Component<IEchartsProps> {
|
||||
export default class LineCharts extends React.Component<IEchartsProps> {
|
||||
public id = null as HTMLDivElement;
|
||||
|
||||
public myChart = null as echarts.ECharts;
|
||||
@@ -27,7 +47,7 @@ export default class LineChart extends React.Component<IEchartsProps> {
|
||||
public componentDidMount() {
|
||||
const { options } = this.props;
|
||||
this.myChart = echarts.init(this.id);
|
||||
this.myChart.setOption(options);
|
||||
this.myChart.setOption(options, true);
|
||||
window.addEventListener('resize', this.resize);
|
||||
}
|
||||
|
||||
@@ -41,7 +61,7 @@ export default class LineChart extends React.Component<IEchartsProps> {
|
||||
|
||||
public refresh = () => {
|
||||
const { options } = this.props;
|
||||
this.myChart.setOption(options);
|
||||
this.myChart.setOption(options, true);
|
||||
}
|
||||
|
||||
public resize = () => {
|
||||
@@ -50,6 +70,6 @@ export default class LineChart extends React.Component<IEchartsProps> {
|
||||
|
||||
public render() {
|
||||
const { height, width } = this.props;
|
||||
return <div ref={id => this.id = id} style={{width: `${width}px`, height: `${height}px`}} />;
|
||||
return <div ref={id => this.id = id} style={{ width: `${width}px`, height: `${height}px` }} />;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user