1
PC-20250623MANY\Administrator
2025-07-08 2f6a967029c293b550e5cb8e39de9ae08b345d44
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<template>
  <div style="width: 100%;height: 100%;">
    <div style="width: 100%;height: 100%;" :id="'main' + ids"></div>
  </div>
</template>
<script>
import * as echarts from 'echarts';
export default {
  props: {
    ids: {
      type: String,
      default: '0',
    },
    colorType: {
      type: Number,
      default: 0,
    }
  },
  data() {
    return {
      myChart: "",
      value: Math.random() * 1000,
      now: new Date(1997, 9, 3),
      oneDay: 24 * 3600 * 1000,
    };
  },
  methods: {
    initCharts() {
      let data = []
      for (var i = 0; i < 1000; i++) {
        data.push(this.randomData());
      }
 
      var chartDom = document.getElementById('main' + this.ids);
      var myChart = echarts.init(chartDom, 'dark');
      var option;
      var greenOrRed = "";
      var greenOrReds = "";
      console.log(this.colorType)
      if (this.colorType > 0) {
        greenOrRed = 'rgba(65,172,117,0.6)'
        greenOrReds = 'rgba(65,172,117,0.05)'
      } else {
        greenOrRed = 'rgba(166,10,36,0.6)'
        greenOrReds = 'rgba(166,10,36,0.05)'
      }
      option = {
        xAxis: {
          show: false,
          type: 'category',
          boundaryGap: false,
 
        },
        yAxis: {
          show: false,
          type: 'value'
        },
        tooltip: {
          show: true,
          extraCssText: '100%;height: 1.5385rem;'
        },
        backgroundColor: 'rgba(0,0,0,0)',
        color: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            {
              offset: 0, color: greenOrRed    // 0% 处的颜色
            }, 
            {
              offset: 1, color: greenOrReds   // 100% 处的颜色
            }
          ],
          globalCoord: false // 缺省为 false
        },
        series: [
          {
            // data: [820, 932, 901, 934, 1000, 900, 1320, 820, 932, 901, 934, 1000, 900,],
            data,
            type: 'line',
            areaStyle: {}
          }
        ]
      };
 
      option && myChart.setOption(option);
    },
    randomData() {
      this.now = new Date(+this.now + this.oneDay);
      this.value = this.value + Math.random() * 21 - 10;
      return {
        name: this.now.toString(),
        value: [
          [this.now.getFullYear(), this.now.getMonth() + 1, this.now.getDate()].join('/'),
          Math.round(this.value)
        ]
      };
    }
  },
  mounted() {
    this.initCharts();
    window.onresize = function () {
      this.myChart.resize();
    };
  }
}
</script>