image.png

  1. initChart1() {
  2. this.optionChart.series = this.line1Data.series;
  3. this.optionChart.xAxis.data = this.line1Data.xAxisData;
  4. this.optionChart.color = this.dataSource1.color;
  5. this.tableDataFormat1 = this.line1Data.tableData;
  6. var chartDom = document.getElementById(this.dataSource1.id);
  7. chartDom.style.height = 334 + 'px'
  8. chartDom.style.width = '100%'
  9. this.myChart1 = echarts.init(chartDom);
  10. this.myChart1.resize()
  11. this.myChart1.clear()
  12. this.myChart1.setOption(this.optionChart);
  13. },
  14. initChart2() {
  15. this.optionChart.series = this.line2Data.series;
  16. this.optionChart.xAxis.data = this.line2Data.xAxisData;
  17. this.optionChart.color = this.dataSource2.color;
  18. this.tableDataFormat2 = this.line2Data.tableData;
  19. var chartDom = document.getElementById(this.dataSource2.id);
  20. chartDom.style.height = 334 + 'px'
  21. chartDom.style.width = '100%'
  22. this.myChart2 = echarts.init(chartDom);
  23. this.myChart2.resize()
  24. this.myChart2.clear()
  25. this.myChart2.setOption(this.optionChart);
  26. },
  27. // 关键代码
  28. setTimeout(() => {
  29. echarts.connect([this.myChart1, this.myChart2])
  30. }, 500);

参考

  1. vue 使用echarts的图表进行联动 echarts.connect()方法无效,
  2. Echarts实现图表联动(多图联动、图表间联动)