选煤厂生产管理平台前端代码
dongyukun
2024-12-10 5cc1d92af645c2f8f4f6d1d3777283b70df78ccd
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
 
<template>
 
  <div id="histogram" ref="histogram"></div>
 
</template>
 
<script>
      export default {
        name:'EchartHistogram',
        data() {
          return {
             HdataMap:{
                legendData:[],
                xAxisData:[],
                 yAxisData:{},
                 typeData:[],
                stackData:[],
                yAxisIndexData:[]
            },
            machart:null,
          };
        },
        props:{
          dataMap:{
            type: Object,
            default:{}
          }
        },
        watch: {
          dataMap(newVal, oldVal){
          this.HdataMap = newVal
          this.changetype()
          }
        },
        methods: {
          changetype() {
             if(Object.keys(this.HdataMap).length===0 ||Object.keys(this.HdataMap.yAxisData).length===0 ){
                    this.machart.setOption({},true)
                  return
             }
 
             var barWidth = this.HdataMap.xAxisData.length<=2?'20%' :''
               var seriesOption=[]
               var yAxis=[]
               for (var num=0;num<=Math.max(...this.HdataMap.yAxisIndexData);num++){ //纵坐标个数
                yAxis.push(
                   {type: 'value',
 
                    }
                )
               }
                for (var kLegend in this.HdataMap.legendData){
                  seriesOption.push( {
                      name: this.HdataMap.legendData[kLegend],
                      type: this.HdataMap.typeData[kLegend],
                      barWidth: barWidth,
                      stack:this.HdataMap.stackData[kLegend],
                      yAxisIndex:this.HdataMap.yAxisIndexData[kLegend],
                      emphasis: {
                      focus: 'series'
                      },
                      data: this.HdataMap.yAxisData[this.HdataMap.legendData[kLegend]]
                  })
              }
               var option = {
                tooltip: {
                  trigger: 'axis',
                  axisPointer: {
                  type: 'shadow'
                  }
                },
                legend: {
                   icon: "roundRect",
                    data: this.HdataMap.legendData
                },
               // color:this.colorData,
 
                toolbox: {
                    show: true,
                },
                xAxis: [
                    {
                    type: 'category',
                    axisTick: { show: false },
                    data: this.HdataMap.xAxisData
                    }
                ],
                yAxis: yAxis,
                series:seriesOption
            };
          this.machart.setOption(option,true);
        },
 
  },
 
  mounted() {
    this.machart = this.$echarts.init(this.$refs.histogram);
    window.addEventListener("resize",  ()=>{
        this.machart.resize();
 
      });
  },
};
 
</script>
<style lang="scss" scoped>
 
#histogram {
  max-height: 700px;
  // max-height: 400px;
  height: 700px;
  margin-top: 50px;
}
</style>