Skip to content

Commit 60bf6a6

Browse files
Merge pull request wuhan2020#131 from pengzh0928/user/pengzh/HoverBehaviour
保证两个折线图联动
2 parents 2001ce7 + 76f6622 commit 60bf6a6

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/components/virusMap/reactEcharts.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export class ReactEcharts extends React.Component<Props> {
4949
}, 0);
5050
}
5151

52+
getEchartsInstance = () => echarts.getInstanceByDom(document.getElementById(this.chartId) as HTMLDivElement)||
53+
echarts.init(document.getElementById(this.chartId) as HTMLDivElement);
54+
5255
public render() {
5356
if (this.chart) {
5457
this.chart.setOption(this.props.chartOptions, false, false);

src/components/virusMap/virusChart.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import React from 'react';
1313
import { ReactEcharts } from './reactEcharts';
1414
import provinceName from '../../data/map/provinces';
15+
import echarts from 'echarts';
1516

1617
type Props = {
1718
data: any;
@@ -70,6 +71,8 @@ const fixChartFontSize = (baseFontSize: number) => {
7071
}
7172

7273
export class VirusChart extends React.Component<Props, Readonly<State>> {
74+
getConfirmedSuspectChart :any
75+
curedDeadChart : any
7376

7477
static defaultProps = {
7578
data: {
@@ -443,6 +446,17 @@ export class VirusChart extends React.Component<Props, Readonly<State>> {
443446
};
444447
}
445448

449+
componentDidMount() {
450+
const {type } = this.props;
451+
if (type === 'pc') {
452+
let confirmedSuspectChart = this.getConfirmedSuspectChart.getEchartsInstance();
453+
let curedDeadChart = this.curedDeadChart.getEchartsInstance();
454+
confirmedSuspectChart.group = 'virusChart';
455+
curedDeadChart.group = 'virusChart';
456+
echarts.connect('virusChart');
457+
}
458+
}
459+
446460
public render() {
447461
const { data, area, path, type } = this.props;
448462
const orderedProvincesData = this.getOrderedTimeData(data.provincesSeries);
@@ -473,6 +487,7 @@ export class VirusChart extends React.Component<Props, Readonly<State>> {
473487
>
474488
<div style={{ width: '100%', height: '50%' }}>
475489
<ReactEcharts
490+
ref={(e) => { this.getConfirmedSuspectChart = e; }}
476491
chartOptions={this.getConfirmedSuspectChartOptions(
477492
orderedProvincesData,
478493
orderedCountryData,
@@ -484,6 +499,7 @@ export class VirusChart extends React.Component<Props, Readonly<State>> {
484499

485500
<div style={{ width: '100%', height: '50%' }}>
486501
<ReactEcharts
502+
ref={(e) => { this.curedDeadChart = e; }}
487503
chartOptions={this.getCuredDeadChartOptions(
488504
orderedProvincesData,
489505
orderedCountryData,

0 commit comments

Comments
 (0)