haoxuan
2023-12-01 ac5ea4c47689788facb2471995621c720a06abc8
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<template>
  <div class="bar-chart">
    <div class="top-view">
      <img src="/cockpitPage/machine-top.png" alt="" />
      <div class="top-title">
        <span>设备负荷对比分析</span>
      </div>
    </div>
    <div class="bar-contents">
      <div class="chart" ref="chart"></div>
    </div>
  </div>
</template>
 
<script>
//引入echart
import * as echarts from 'echarts'
export default {
  components: {
  },
  props: {},
  data() {
    return {
      chartData: {
        datax: ['设备1', '设备2', '设备3', '设备4', '设备5', '设备6'],
        datay: [10, 20, 15, 38, 47, 50, 20],
      }
    };
  },
  mounted() {
    this.pieChart('chart', this.chartData)
  },
  watch: {},
  methods: {
    //在职
    pieChart(chartName, data) {
      let chartDom = this.$refs[chartName]
      let myChart = echarts.init(chartDom);
      let option;
      let lineColor = '#35ddc74d'
      if (data) {
        option = {
          color: ['#00FFFF', '#dcb018'],
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'none'
            },
          },
          grid: {
            right: "80px",
            bottom: '60px',
            left: '60px',
            top: '30px',
          },
          dataZoom: [
            {
              type: 'inside',
              // show: true, //显示滚动条
              start: 0,
              end: 100,
              yAxisIndex: 0,
              minSpan: 20,
              maxSpan: 100,
              // handleSize: 8
            },
            {
              //   type: 'slider', //两个一个是slider,一个是inside,slider是增加滚动条以及鼠标拖动滚动条功能,inside则是鼠标滚轮滚动滚动条。
              type: 'inside',
              // show: true,
              // realtime : true,
              yAxisIndex: 0,
              minSpan: 20,
              maxSpan: 100,
              start: 0,
              end: 100
            },
          ],
          legend: {
            itemWidth: 8,
            itemHeight: 8,
            itemGap: 35,//间距
            bottom: '5px',
            left: 'center',
          },
          yAxis: [
            {
              type: 'category',
              axisTick: {
                show: false
              },
              axisLine: {
                show: true,
                lineStyle: {
                  color: lineColor,
                }
              },
              axisLabel: {
                // rotate:45,
                margin: 10,
                show: true,
                textStyle: {
                  color: function (params, index) {
                    let colorList = ['#dcb018', '#00FFFF']
                    if (index % 2 == 0) {
                      return colorList[0]
                    } else {
                      return colorList[1]
                    }
                  }
                },
              },
              data: data.datax ? data.datax : [],
            }
          ],
          xAxis: [
            {
              type: '',
              name: '',
              // min: data.yAxis[0].min?data.yAxis.min:0,
              minInterval: 1,//坐标轴是整数
              max: Math.ceil(eval(`Math.max(${data.datay})`) / 5) * 5,//数据最大值加3
              interval: Math.ceil(eval(`Math.max(${data.datay})`) / 6) * 6 / 6,
              position: 'left',
              axisLine: {
                show: true,
                lineStyle: {
                  color: '#0a112B',
                }
              },
              nameTextStyle: {
                color: "#00FFFF",
              },
              splitLine: {
                show: true,
                lineStyle: {
                  // 使用深浅的间隔色
                  color: lineColor,
                }
              },
              axisTick: {
                show: false
              },
 
              axisLabel: {
                textStyle: {
                  color: '#00FFFF'
                },
                formatter: '{value}%'
              }
            },
          ],
          series: [
            {
              type: 'bar',
              name: '',
              barWidth: '15',
              label:{
                show:true,
                position:'right',
                color: '#00FFFF'
              },
              itemStyle: {
                normal: {
                  //柱形图圆角,初始化效果
                  barBorderRadius: [4, 4, 0, 0],
                  color: function (params) {
                    let colorList = ['#dcb018', '#00FFFF']
                    if (params.dataIndex % 2 == 0) {
                      return colorList[0]
                    } else {
                      return colorList[1]
                    }
                  }
                },
              },
              data: data.datay,
            },
          ]
        };
 
        option && myChart.setOption(option);
      } else {
        option = {};
        myChart.setOption(option, true);
      }
    },
  },
};
</script>
 
<style scoped lang="scss">
.bar-chart {
  width: 100%;
  height: calc(100% - 0px);
  padding: 0px 0 0;
  border: 1px solid #00FFFF;
  box-sizing: border-box;
  position: relative;
  .top-view {
      height:38px;
      margin-top: -1px;
      margin-left: -1px;
      position: relative;
      left:0;
      top:0;
      .top-title {
        width: calc(100% - 10px);
        margin: auto;
        height:38px;
        line-height:38px;
        position:absolute;
        top:0;
        left:10px;
        color: #01f7fd;
        font-size: 14px;
        font-family: "Arial Negreta", "Arial Normal", "Arial";
        font-weight: 700;
      }
    }
  .bar-contents {
    width: 100%;
    height: calc(100% - 40px);
    .chart {
      width: 100%;
      height: 100%;
    }
  }
}
</style>