haoxuan
2023-12-01 054ded9f11161462013db20eb213bb015f7cb978
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
<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 {
 
    };
  },
  mounted() {
    let chartData={
      datax:['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
      datay:[120, 200, 150, 80, 70, 110, 130]
    }
    this.pieChart('chart',chartData)
  },
  watch: {},
  methods: {
    //在职
    pieChart(chartName,data){
          let chartDom = this.$refs[chartName]
          let myChart = echarts.init(chartDom);
          let option;
          if(data){
            option = {
              color:['#618DF8'],
              tooltip: {
                trigger: 'axis',
                axisPointer: {
                  type: 'none'
                }
              },
              grid: {
                right: "11%",
                bottom:'21%',
              },
              dataZoom: [
                {
                  type: 'inside',
                  // show: true, //显示滚动条
                  start:0,
                  end: 100,
                  xAxisIndex: 0,
                  minSpan:20,
                  maxSpan:100,
                  // handleSize: 8
                },
                {
                  //   type: 'slider', //两个一个是slider,一个是inside,slider是增加滚动条以及鼠标拖动滚动条功能,inside则是鼠标滚轮滚动滚动条。
                  type: 'inside',
                  // show: true,
                  // realtime : true,
                  xAxisIndex: 0,
                  minSpan:20,
                  maxSpan:100,
                  start: 0,
                  end: 100
                },
              ],
              legend: {
                itemWidth: 12,
                itemHeight: 12,
                itemGap: 35,//间距
                // data:data.legend?[
                //   {
                //     name:data.legend.data[0],
                //     icon: 'roundRect',
                //   },
                // ]:[]
              },
              xAxis: [
                {
                  type: 'category',
                  axisTick: {
                    show: false
                  },
                  axisLine: {
                    show: true,
                    lineStyle: {
                      color:'#EAEAEA',
                    }
                  },
                  axisLabel:{
                    rotate:45,
                    margin: 12,
                    show: true,
                    textStyle: {
                      color: '#9B9B9B'
                    },
                  },
                  data: data.datax?data.datax:[],
                }
              ],
              yAxis: [
                {
                  type: '',
                  name: 'yyy',
                  // 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})`)/5)*5 / 5,
                  position: 'left',
                  axisLine: {
                    show: true,
                    lineStyle: {
                      color:'#EAEAEA',
                    }
                  },
                  nameTextStyle:{
                    color:"#9B9B9B",
                  },
                  splitLine: {
                    show: true,
                    lineStyle: {
                      // 使用深浅的间隔色
                      color: '#EAEAEA',
                    }
                  },
                  axisTick: {
                    show: false
                  },
                  axisLabel: {
                    textStyle: {
                      color: '#9B9B9B'
                    },
                    formatter: ''
                  }
                }
              ],
              series:[
                {
                  type: '',
                  name: 'y',
                  barWidth: '20%',
                  itemStyle: {
                    normal: {
                      //柱形图圆角,初始化效果
                      barBorderRadius:[4, 4, 0, 0],
                    }
                  },
                  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% - 10px);
  padding:10px 0 0;
  .bar-contents{
    width:100%;
    height:calc(100% - 60px);
    border:1px solid #00FFFF;
    box-sizing: border-box;
    .chart{
        width: 100%;
        height:100%;
      }
  }
}
</style>