Line.vue 3.19 KB
Newer Older
shabai517's avatar
shabai517 committed
1
2
3
4
5
6
7
8
9
10
11
12
<template>
  <div>
        <a @click="changeDate('year')">Year</a> <a @click="changeDate('month')">Month</a>
        <chart class="test" :options="options" :auto-resize="true"></chart>
  </div>
    
</template>
<script>
export default {
  data: function () {
    //let data = 
    return {
shabai517's avatar
shabai517 committed
13
14
      lineYearApi:'http://ves-pg-41:9020/stats/SUBMISSIONS_PER_YEAR',
      lineMonthApi:'http://ves-pg-41:9020/stats/SUBMISSIONS_PER_MONTH',
shabai517's avatar
shabai517 committed
15
16
17
18
19
20
21
22
23
24
      options: {
        title: {
            text: 'Beijing AQI'
        },
        tooltip: {
            trigger: 'axis'
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
shabai517's avatar
shabai517 committed
25
            data: ['null','null']
shabai517's avatar
shabai517 committed
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
        },
        yAxis: {
            splitLine: {
                show: false
            }
        },
        /*
        toolbox: {
            left: 'center',
            feature: {
                dataZoom: {
                    yAxisIndex: 'none'
                },
                restore: {},
                saveAsImage: {}
            }
        },*/
        dataZoom: [{
            startValue: '2014-06-01'
        }, {
            type: 'inside'
        }],
        /*
        visualMap: {
            top: 10,
            right: 10,
            pieces: [{
                gt: 0,
                lte: 50,
                color: '#096'
            }, {
                gt: 50,
                lte: 100,
                color: '#ffde33'
            }, {
                gt: 100,
                lte: 150,
                color: '#ff9933'
            }, {
                gt: 150,
                lte: 200,
                color: '#cc0033'
            }, {
                gt: 200,
                lte: 300,
                color: '#660099'
            }, {
                gt: 300,
                color: '#7e0023'
            }],
            outOfRange: {
                color: '#999'
            }
        },*/
        series: [
              {
shabai517's avatar
shabai517 committed
82
                  name:'SUBMISSIONS_PER_YEAR',
shabai517's avatar
shabai517 committed
83
                  type:'line',
shabai517's avatar
shabai517 committed
84
                  data:[0,0]
shabai517's avatar
shabai517 committed
85
86
87
88
89
90
91
92
              }
        ]
      }
    }
  },
  methods:{
      changeDate(item){
          if(item == 'year'){
shabai517's avatar
shabai517 committed
93
94
95
96
97
98
99
100
              this.$http
                  .get(this.lineYearApi)
                  .then(function(res){
                    this.$bus.$emit('show-line', res.body);
                  },function(err){

                  });
             
shabai517's avatar
shabai517 committed
101
102
          }
          if(item == 'month'){
shabai517's avatar
shabai517 committed
103
104
105
106
107
108
109
110
             this.$http
                  .get(this.lineMonthApi)
                  .then(function(res){
                    this.sunburstPrideShow=false;
                    this.$bus.$emit('show-line', res.body);
                  },function(err){

                  });
shabai517's avatar
shabai517 committed
111
          }
shabai517's avatar
shabai517 committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
      },
      setOptions(data){
        let xValue = [];
        let yValue = [];
        for(let i=0; i<data.length; i++){
          xValue.push(data[i].key);
          yValue.push(data[i].value);
        }
        this.options.xAxis.data = xValue;
        this.options.series[0].data = yValue;
    }
  },
  created(){
    this.$bus.$on('show-line', this.setOptions);
shabai517's avatar
shabai517 committed
126
  },
shabai517's avatar
shabai517 committed
127
128
129
  beforeCreate:function(){
    this.$bus.$off('show-line');
  }
shabai517's avatar
shabai517 committed
130
131
132
133
134
135
136
137
138
}
</script>

<style>
.echarts.test  {
  height: 400px !important;
  width: auto !important;
}
</style>