yangfeng
2023-12-02 d69724b8ba43312b3e794ad2d63a2493972f02c0
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
<template>
  <div class="bar-chart">
    <ChartTitle name="物料需求统计"></ChartTitle>
    <div class="bar-contents">
      <div class="chart" ref="chart"></div>
    </div>
  </div>
</template>
 
<script>
import ChartTitle from "@/views/cockpitPage/components/ChartTitle.vue";
//引入echart
import * as echarts from 'echarts'
export default {
  components: {
    ChartTitle,
  },
  props: {},
  data() {
    return {
      chartData:{
        datax:['产品1', '产品2', '产品3', '产品4','产品5', '产品6'],
        datay:[120, 200, 150, 380, 470, 150, 230],
      }
    };
  },
  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})`)/7)*7 / 7,
                  position: 'left',
                  axisLine: {
                    show: true,
                    lineStyle: {
                      color:'#0a112B',
                    }
                  },
                  nameTextStyle:{
                    color:"#00FFFF",
                  },
                  splitLine: {
                    show: true,
                    lineStyle: {
                      // 使用深浅的间隔色
                      color: lineColor,
                    }
                  },
                  axisTick: {
                    show: false
                  },
                
                  axisLabel: {
                    textStyle: {
                      color: '#00FFFF'
                    },
                    
                  }
                },
              ],
              series:[
                {
                  type: 'bar',
                  name: '',
                  barWidth: '15',
                  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% - 20px);
  padding:20px 0 0;
  .bar-contents{
    width:100%;
    height:calc(100% - 60px);
    border:1px solid #00FFFF;
    box-sizing: border-box;
    .chart{
        width: 100%;
        height:100%;
      }
  }
}
</style>