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
<template>
  <div class="linechart-box">
    <div class="common-form d-b-c">
      <div style="font-size: 18px;">活动数据</div>
      <el-radio-group v-model="rankingTime" size="mini" @change="getData(rankingTime)">
        <el-radio-button v-for="item in timeList" :key="item.value" :label="item.value">{{ item.label }}</el-radio-button>
      </el-radio-group>
    </div>
    <div>
        <div class="Echarts"><div id="ActivityLineChart"></div></div>
    </div>
  </div>
</template>
 
<script>
import StatisticsApi from '@/api/statistics.js';
export default {
  data() {
    return {
      rankingTime: 'year',
      timeList: [
        { value: 'lately7', label: '近7天' },
        { value: 'lately30', label: '近30天' },
        { value: 'month', label: '本月' },
        { value: 'year', label: '本年' }
      ],
 
      /*数据对象*/
      dataList: null,
      /*交易统计图表对象*/
      myChart: null,
      /*图表数据*/
      option: {
        title: {
          //text: 'ECharts 入门示例'
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        tooltip: {
          trigger: 'axis'
        },
        yAxis: {}
      }
    };
  },
  mounted() {
    this.myEcharts();
  },
  methods: {
 
    /*选择时间*/
    changeDate() {
      this.getData();
    },
 
    myEcharts() {
      // 基于准备好的dom,初始化echarts实例
      this.myChart = this.$echarts.init(document.getElementById('ActivityLineChart'));
      /*获取列表*/
      this.getData();
    },
 
    /*格式数据*/
    createOption() {
      if (!this.loading) {
        let names = [];
        let xAxis = this.dataList.days;
        let series1 = [];
        this.dataList.data.forEach(item => {
          series1.push(item.total);
        });
        names = ['新增活动数'];
 
        // 指定图表的配置项和数据
        this.option.xAxis = {
          type: 'category',
          boundaryGap: false,
          data: xAxis
        };
        this.option.color=["#5d7092", "#409EFF"];
 
        this.option.legend = {
          data: [{ name: names[0], color: '#ccc' }]
        };
        this.option.series = [
          {
            name: names[0],
            type: 'line',
            data: series1,
            lineStyle: {
              color: '#5d7092'
            }
          }
        ];
 
        this.myChart.setOption(this.option);
        this.myChart.resize();
      }
    },
 
    /*获取列表*/
    getData() {
      let self = this;
      self.loading = true;
      StatisticsApi.getActivityByDate(
        {
          date: self.rankingTime,
        },
        true
      )
        .then(res => {
          self.dataList = res.data;
          self.loading = false;
          self.createOption();
        })
        .catch(error => {});
    }
  }
};
</script>
 
<style scoped="scoped">
  .Echarts{ box-sizing: border-box;}
  .Echarts>div{ width: 100%; height: 360px; box-sizing: border-box;}
</style>