Skip to content

Commit 6b40b03

Browse files
committed
引入echarts,开发一周内访问数据折线图
1 parent cfefcc0 commit 6b40b03

File tree

2 files changed

+52
-16
lines changed

2 files changed

+52
-16
lines changed

src/components/index.vue

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<template>
22
<div class="RightContent">
33
<div class="ArticleList">
4+
<div id="lineChart" class="lineChart"></div>
5+
<div id="mapChart" class="lineChart"></div>
46
<!--表格操作栏-->
57
<el-table :data="blogVisitList" style="width: 100%">
68
<el-table-column prop="ip" label="访客IP"></el-table-column>
@@ -20,9 +22,26 @@
2022
<script>
2123
export default {
2224
name: "index",
23-
data:function (){
25+
data: function () {
2426
return {
25-
blogVisitList:[]
27+
blogVisitList: [],
28+
lineChartOption: {
29+
title: {text: '数据趋势'},
30+
tooltip: {
31+
trigger: 'axis'
32+
},
33+
legend:{
34+
type:'plain'
35+
},
36+
xAxis: {data: []},
37+
yAxis: {},
38+
series: [{
39+
name: '博客访问量(人/天)', type: 'line', data: [],
40+
itemStyle: {normal: {label: {show: true}}}
41+
}]
42+
},
43+
mapChartOption:{
44+
}
2645
}
2746
},
2847
methods: {
@@ -35,42 +54,57 @@ export default {
3554
That.blogVisitList = data;
3655
}
3756
});
38-
57+
},
58+
setLineChart: function () {
59+
var that = this;
60+
let lineChart = this.$echarts.init(document.getElementById('lineChart'));
3961
this.SQAjax({
4062
Url: '/api/visitCount/foreend',
41-
RequestData:{
42-
endTime:'2021/11/23',
43-
dayNum:3
63+
RequestData: {
64+
endTime: '2021/11/24',
65+
dayNum: 7
4466
},
4567
Success: function (data) {
46-
console.log('近三天内访客',data);
68+
let dates = [], readings = [];
69+
data.forEach(function (item) {
70+
dates.push(item.time);
71+
readings.push(item.reading);
72+
});
73+
that.lineChartOption.xAxis.data = dates.reverse();
74+
that.lineChartOption.series[0].data = readings.reverse();
75+
lineChart.setOption(that.lineChartOption);
4776
}
4877
});
4978
},
50-
Delete:function (Id) {
79+
Delete: function (Id) {
5180
var That = this;
5281
5382
That.SQAjax({
54-
Url:'/api/visitDelete/backend',
55-
RequestData:{
56-
_id:Id
83+
Url: '/api/visitDelete/backend',
84+
RequestData: {
85+
_id: Id
5786
},
58-
Success:function (data) {
87+
Success: function (data) {
5988
That.$message('删除成功');
6089
That.getBlogVisitList();
6190
}
6291
});
6392
},
6493
},
65-
mounted:function () {
94+
mounted: function () {
6695
this.getBlogVisitList();
67-
this.bus.$emit('Topbar',{
68-
MenuHighLight:'0'
96+
this.setLineChart();
97+
98+
this.bus.$emit('Topbar', {
99+
MenuHighLight: '0'
69100
});
70101
}
71102
}
72103
</script>
73104

74105
<style scoped>
75-
106+
.lineChart {
107+
width: 100%;
108+
height: 400px;
109+
}
76110
</style>

src/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import App from './App'
77
import router from './router'
88
import './assets/css/base.less'
99
import CommonFunction from './util/util'
10+
import * as echarts from 'echarts'
1011

1112
Vue.config.productionTip = false
1213
Vue.use(CommonFunction);
1314
Vue.prototype.bus = new Vue;
15+
Vue.prototype.$echarts = echarts;
1416

1517
// 注册ElementUI
1618
Vue.use(ElementUI);

0 commit comments

Comments
 (0)