surprise
2024-03-05 1ce1b525e7470ebaaeb0d5cd1e59bd905c1a7114
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
<template>
  <div class="echart1_box">
    <div>
      <el-select v-model="model" placeholder="" @change="getEchartsDta">
        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
        </el-option>
      </el-select>
    </div>
    <div class="echart">
      <div id="echart1"> </div>
    </div>
  </div>
</template>
 
<script>
import {
  zhangzitou_selectInfos
} from '../api/api.js'
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      chartData: [],
      siteOption: [],
      model: null,
      options: [],
    };
  },
  mounted() {
    this.initChart();
  },
  //方法集合
  methods: {
    async initChart() {
      const data = await zhangzitou_selectInfos();
      if (data.code != 200) return;
      if (this.siteOption.length <= 0) {
        var std = [];
        for (var i in data.result) {
          var val = data.result[i]
          if (std.indexOf(val.line) == -1) {
            std.push(val.line)
          }
 
        }
      }
      var str = [];
      for (var i in std) {
        str.push({
          label: std[i],
          value: std[i]
        })
      }
      this.options = str;
      this.model = this.options[0].value
      this.getEchartsDta();
    },
    async getEchartsDta() {
      const data = await zhangzitou_selectInfos({ line: this.model });
      if (data.code != 200) return;
      var std =[];
      for(var i in data.result){
        var val = data.result[i]
        std.push(
          { value: val.count, name: val.type },
        )
      }
      this.lineChart(std)
    },
 
 
 
 
 
 
 
    lineChart(res) {
      let option = {
        title: {
 
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        series: [
          {
            name:  this.model,
            type: 'pie',
            radius: '50%',
            data:  res,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };
      let myChart = this.$echarts.init(document.getElementById("echart1"));
      myChart.setOption(option);
      window.addEventListener("resize", function () {
        myChart.resize();
      });
    },
  },
  created() { },
};
</script>
<style lang="less" scoped>
//@import url(); 引入公共css类
.echart1_box {
  width: 100%;
  height: 100%;
  // position: absolute;
}
 
.echart {
  position: relative;
  width: 100%;
  margin-top: 5px;
  height: calc(100% - 50px);
//  background: skyblue;
 #echart1{
  width: 100%;
  height: 100%;
 }
}
</style>