baotian
2024-06-04 b959135a1139fb66646523d92e5bd20c5910f283
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
231
<template>
  <div class="box-container" id="echarts5"></div>
</template>
  
  <script>
export default {
  props:{
    produceCompletionData:{
      type:Array,
      default:()=>[]
    }
  },
  data() {
    return {
      option: {},
      myChart: {},
      timechartes: null,
    };
  },
  watch:{
    produceCompletionData(val){
      let xData=[],yData1=[],yData2=[];
      val.forEach(item => {
        xData.push(item.month)
        yData1.push(item.planCompletionNum)
        yData2.push(item.planCompletionRate)
      });
      this.$set(this.option.xAxis,'data',xData)
      this.$set(this.option.series[0],'data',yData1)
      this.$set(this.option.series[1],'data',yData2)
      this.myChart.setOption(this.option);
    }
  },
  mounted() {
    this.myChart = this.$echarts.init(document.getElementById("echarts5"));
    this.option = {
      tooltip: {
        trigger: "axis",
        formatter:
          '{b0}月<br /><a style="display:inline-block;width:10px;height:10px;background:linear-gradient(to bottom,#13e5f2,#01afba);border-radius:50%"></a> {a0}: {c0}<br /><a style="display:inline-block;width:10px;height:10px;background:linear-gradient(to bottom,#fff,#eee);border-radius:50%"></a> {a1}: {c1}%',
        backgroundColor: "rgba(0,0,0,0.7)",
        textStyle: {
          color: "#fff",
        },
      },
      grid: {
        top: "15%",
        bottom: "15%",
        left: "16%",
        right: "15%"
      },
      xAxis: {
        data: [ ],
        type: "category",
        axisLabel: {
          color: "#fff",
          interval:0,
          // formatter: '{value}月'
        },
        axisTick:{
          show:false
        },
        axisLine:{
          lineStyle:{
            color:'rgba(255,255,255,0.5)'
          }
        }
      },
      yAxis: [
        {
          type: "value",
          // name: "报警次数",
          position:'left',
          axisLine: {
            show: true,
            lineStyle: {
              color: 'rgba(255,255,255,0.5)',
            },
          },
          axisLabel: {
            show:true,
            margin: 5,
            color: "#fff",
            // formatter: '{value}%'
          },
          alignTicks: true,
          nameTextStyle: {
            color: "#fff",
          },
          splitLine:{
            lineStyle:{
              color:'rgba(255,255,255,0.5)'
            }
          }
        },
        {
          show:true,
          type: "value",
          position:'right',
          // name: "持续时长",
          axisLine: {
            show: false,
            lineStyle: {
              color: "rgba(255,255,255,0.5)",
            },
          },
          axisLabel: {
            show:true,
            color: "#fff",
            formatter: '{value}%'
          },
          nameTextStyle: {
            color: "#fff",
          },
          splitLine:{
            lineStyle:{
              color:'rgba(255,255,255,0)'
            }
          }
        },
      ],
      series: [
        {
          name: "生产完成数",
          type: "bar",
          data: [],
          yAxisIndex: 0,
          color: {
            type: "linear",
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: "#13e5f2", // 0% 处的颜色
              },
              {
                offset: 1,
                color: "#01afba", // 100% 处的颜色
              },
            ],
          },
        },
        {
          name: "生产完成率",
          type: "line",
          data: [],
          showSymbol:false,
          yAxisIndex: 1,
          color: 'rgba(255,255,255,0.85)',
          lineStyle:{
            width:3
          }
        },
      ],
      // animation: true,
      // dataZoom: [
      //   {
      //     xAxisIndex: 0, //这里是从X轴的0刻度开始
      //     show: false, //是否显示滑动条,不影响使用
      //     type: "inside", // 这个 dataZoom 组件是 slider 型 dataZoom 组件
      //     startValue: 0, // 从头开始。
      //     endValue: 5, // 一次性展示几个。
      //   },
      // ],
    };
    this.myChart.setOption(this.option);
    const that=this
    window.addEventListener('resize',()=>{
      that.myChart.resize();
    })
    // this.barChartScrolling();
    // this.defineEvent()
    // window.addEventListener("resize",  ()=> {
    //   this.myChart.resize();
    // });
  },
  methods: {
    // 水平滚动
    barChartScrolling() {
      const x = this.option.xAxis.data;
      const y1 = this.option.series[0].data;
      const y2 = this.option.series[1].data;
      if (x.length > 0 && y1.length > 0 && y2.length > 0) {
        this.timechartes = setInterval(this.handle, 1500);
      }
    },
 
    handle() {
      const option = this.option;
      const x = this.option.xAxis.data;
      // 每次向后滚动一个,最后一个从头开始。
      if (option.dataZoom[0].endValue == x.length) {
        this.$set(option.dataZoom[0], "endValue", 5);
        this.$set(option.dataZoom[0], "startValue", 0);
      } else {
        this.$set(
          option.dataZoom[0],
          "endValue",
          option.dataZoom[0].endValue + 1
        );
        this.$set(
          option.dataZoom[0],
          "startValue",
          option.dataZoom[0].startValue + 1
        );
      }
      this.myChart.setOption(option);
    },
 
    // 鼠标触摸轮播悬停事件
    defineEvent() {
      // 鼠标移出轮播继续
      this.myChart.on("mouseout", () => {
        if (this.timechartes) clearInterval(this.timechartes);
        this.timechartes = setInterval(this.handle, 1500);
      });
 
      // 鼠标进入轮播悬停
      this.myChart.on("mouseover", () => {
        clearInterval(this.timechartes);
      });
    },
  },
};
</script>
  
  <style>
</style>