Xxxu
2020-07-03 1ac6ef52a03f25f9def9f6a2594d2a8196aa77f6
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<template>
    <div>
      <div id='singleDataChart' style='height:200px'></div>
    </div>
</template>
<script>
import echarts from 'echarts'
export default {
  data () {
    return {
      xAxisList: ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00'],
      powerList: [620, 952, 981, 634, 190, 1830, 620, 952, 981, 634, 190, 190, 1830],
      lightList: [820, 932, 901, 934, 1290, 1330, 1320, 820, 932, 901, 934, 1290, 1330]
    }
  },
  activated () {
    this.init()
    this.drawChart()
  },
  methods: {
    init () {
      var h = window.innerHeight || document.body.clientHeight
      var body = document.getElementById('singleDataChart')
      var num = (h / 3) - 100
      body.style.height = num + 'px'
    },
    drawChart () {
      var option = {
        legend: {
          orient: 'horizontal',
          position: 'center',
          top: 10,
          data: ['电源亮度', '电源有功功率'],
          textStyle: {
            color: 'white'
          }
        },
        xAxis: {
          axisLine: {
            lineStyle: {
              color: 'white'
            }
          },
          type: 'category',
          boundaryGap: false,
          data: this.xAxisList
        },
        tooltip: {
          trigger: 'axis',
          position: function (pt) {
            return [pt[0], '10%']
          }
        },
        yAxis: {
          axisLine: {
            lineStyle: {
              color: 'white'
            }
          },
          type: 'value',
          axisLabel: {
            formatter: function (param) {
              return param / 10
            }
          },
          splitLine: {
            show: false
          }
        },
        series: [
          {
            name: '电源有功功率',
            data: this.powerList,
            type: 'line',
            symbol: 'circle', // 折线点设置为实心点
            symbolSize: 10, // 设定实心点的大小
            lineStyle: {
              width: 5
            },
            itemStyle: {
              normal: {
                color: '#68A2D1', // 折线点的颜色
                lineStyle: {
                  color: '#68A2D1' // 折线的颜色
                }
              }
            },
            areaStyle: {
              normal: {
                // 颜色渐变函数 前四个参数分别表示四个位置依次为左、下、右、上
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: 'rgba(0,0,0,0.2)'
                  },
                  {
                    offset: 0.5,
                    color: 'rgba(25,64,121,.7)'
                  },
                  {
                    offset: 1,
                    color: '#1B3C72'
                  }
                ])
              }
            }
          },
          {
            name: '电源亮度',
            data: this.lightList,
            symbol: 'circle', // 折线点设置为实心点
            symbolSize: 10, // 设定实心点的大小
            type: 'line',
            lineStyle: {
              width: 5
            },
            itemStyle: {
              normal: {
                color: '#F81136', // 折线点的颜色
                lineStyle: {
                  color: '#F81136' // 折线的颜色
                }
              }
            }
          }
        ]
      }
 
      var singleDataChart = echarts.init(
        document.getElementById('singleDataChart')
      )
      singleDataChart.setOption(option)
    }
  }
}
</script>
<style>
</style>