• 在vue中插入echarts图表


    <template>
      <div
        class="echart"
        ref="mychart1"
        id="mychart1"
        :style="{ float: 'left', width: '100%', height: '400px' }"
      >div>
      <div
        class="echart"
        ref="mychart2"
        id="mychart2"
        :style="{ float: 'left', width: '100%', height: '400px' }"
      >div>
    template>
    
    <script>
    import * as echarts from 'echarts';
    // import {ref,onMounted} from vue
    export default {
      
      mounted() {
        this.$nextTick(() => {
          this.initEcharts();
        });
    
      },
      methods: {
        initEcharts() {
          const chartDom1 = this.$refs.mychart1;
          const myChart1 = echarts.init(chartDom1);
          const option1 = {
            xAxis: {
              type: 'category',
              data:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
             21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,
             39,40,41,42,43,44,45,46,47,48,49,]
            },
            yAxis: {
              type: 'value'
            },
            series: [
              {
                data:[0.146299484,0.488812392,0.853700516,0.853700516,0.853700516,0.853700516,0.853700516,0.853700516,0.853700516,
        0.853700516,0.853700516,0.853700516,0.905335628,0.908777969,0.908777969,0.91222031,0.91394148,0.91394148,0.91394148,
        0.91394148,0.917383821,0.919104991,0.919104991,0.919104991,0.919104991,0.920826162,0.920826162,0.920826162,0.920826162,
        0.920826162,0.920826162,0.920826162,0.920826162,0.920826162,0.920826162,0.922547332,0.922547332,0.920826162,0.920826162,
        0.919104991,0.920826162,0.920826162,0.920826162,0.920826162,0.920826162,0.920826162,0.920826162,0.920826162,0.920826162,
        0.920826162,],
                type: 'line'
              }
            ]
          };
          option1 && myChart1.setOption(option1);
    
          const chartDom2 = this.$refs.mychart2;
          const myChart2 = echarts.init(chartDom2);
          const option2 = {
            xAxis: {
              type: 'category',
              data:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
             21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,
             39,40,41,42,43,44,45,46,47,48,49,]
            },
            yAxis: {
              type: 'value'
            },
            series: [
              {
                data:[0.746837711,0.746837711,0.746837711,0.746837711,0.746837711,0.746837711,0.746837711,0.746837711,
        0.746837711,0.746837711,0.746837711,0.746837711,0.746837711,0.746837711,0.746837711,0.746837711,0.746837711,
        0.746837711,0.746837711,0.291002565,0.288495182,0.288172036,0.286044006,0.285230208,0.28466754,0.284258943,
        0.28390811,0.283597514,0.28333019,0.283045125,0.282801505,0.282566763,0.282336899,0.282146023,0.281934799,
        0.281753167,0.281543406,0.281496848,0.281532406,0.281580297,0.281468421,0.281410495,0.281327578,0.281245982,
        0.281173373,0.28107471,0.281006722,0.280915136,0.280841162,0.280741451,],
                type: 'line'
              }
            ]
          };
          option2 && myChart2.setOption(option2);
    
          
    
          window.addEventListener("resize", () => {
            myChart1.resize();
            myChart2.resize();
          });
        }
      }
    };
    script>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91

    这段代码是一个Vue.js组件,用于渲染两个ECharts图表(mychart1和mychart2)。让我详细解释每个部分的作用: