Skip to content

Commit b00672c

Browse files
committed
echarts折线图demo
1 parent 8dd6fd3 commit b00672c

File tree

8 files changed

+289
-63
lines changed

8 files changed

+289
-63
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = {
2828
"import/no-unresolved": 0,
2929
"import/extensions": 0,
3030
"import/no-dynamic-require": 0,
31-
"import/no-duplicates": 0
31+
"import/no-duplicates": 0,
32+
"vue/max-attributes-per-line": 0
3233
}
3334
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"babel-preset-env": "^1.6.1",
2828
"clean-webpack-plugin": "^0.1.17",
2929
"css-loader": "^0.28.5",
30-
"element-ui": "^2.0.8",
30+
"echarts": "^3.8.5",
31+
"element-ui": "^2.0.9",
3132
"eslint": "^4.13.1",
3233
"eslint-config-airbnb-base": "^12.1.0",
3334
"eslint-plugin-html": "^4.0.1",

src/components/layout1.vue

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="layout">
33
<el-container style="min-height: 100vh">
44
<el-header>
5-
<div width="200px" class="logo"></div>
5+
<div width="200px" class="logo"/>
66
</el-header>
77
<el-container>
88
<el-aside width="200px">
@@ -22,7 +22,7 @@
2222
<template v-if="item.sub">
2323
<el-submenu :index="item.key" :key="item.key">
2424
<template slot="title">
25-
<i class="el-icon-location"></i>
25+
<i class="el-icon-location"/>
2626
<span>{{ item.name }}</span>
2727
</template>
2828
<el-menu-item v-for="subItem in item.sub" :index="subItem.key" :key="subItem.key">
@@ -32,7 +32,7 @@
3232
</template>
3333
<template v-else>
3434
<el-menu-item :index="item.key" :key="item.key">
35-
<i class="el-icon-menu"></i>
35+
<i class="el-icon-menu"/>
3636
<span slot="title">{{ item.name }}</span>
3737
</el-menu-item>
3838
</template>
@@ -44,7 +44,7 @@
4444
</el-aside>
4545
<el-container>
4646
<el-main>
47-
<slot name="content"></slot>
47+
<slot name="content"/>
4848
</el-main>
4949
<el-footer>July Design ©2017 Created by July</el-footer>
5050
</el-container>
@@ -54,48 +54,48 @@
5454
</template>
5555

5656
<script>
57-
const operateUrl = 'claa/menulist';
57+
const operateUrl = 'claa/menulist';
5858
59-
export default {
60-
name: 'layout',
61-
data() {
62-
return {
63-
defaultActive: 'item1'
64-
};
65-
},
59+
export default {
60+
name: 'Layout',
61+
data() {
62+
return {
63+
defaultActive: 'item1'
64+
};
65+
},
6666
67-
created() {
68-
this.defaultActive = this.$route.path.split('/')[1] ? this.$route.path.split('/')[1] : 'item1';
69-
},
70-
mounted() {
71-
this.doQuery();
72-
},
67+
created() {
68+
this.defaultActive = this.$route.path.split('/')[1] ? this.$route.path.split('/')[1] : 'item1';
69+
},
70+
mounted() {
71+
this.doQuery();
72+
},
7373
74-
computed: {
75-
menu() {
76-
return this.$store.state.menu.menuList;
77-
}
74+
computed: {
75+
menu() {
76+
return this.$store.state.menu.menuList;
77+
}
78+
},
79+
methods: {
80+
handleOpen(key, keyPath) {
81+
console.log(key, keyPath);
82+
},
83+
handleClose(key, keyPath) {
84+
console.log(key, keyPath);
7885
},
79-
methods: {
80-
handleOpen(key, keyPath) {
81-
console.log(key, keyPath);
82-
},
83-
handleClose(key, keyPath) {
84-
console.log(key, keyPath);
85-
},
86-
doQuery() {
87-
const param = {
88-
loadingFlag: true,
89-
url: operateUrl,
90-
method: 'POST',
91-
data: {
92-
type: 'on'
93-
}
94-
};
95-
this.$store.dispatch('fetch', param);
96-
}
86+
doQuery() {
87+
const param = {
88+
loadingFlag: true,
89+
url: operateUrl,
90+
method: 'POST',
91+
data: {
92+
type: 'on'
93+
}
94+
};
95+
this.$store.dispatch('fetch', param);
9796
}
98-
};
97+
}
98+
};
9999
</script>
100100

101101
<style lang="scss" scoped>

src/pages/item1/item1.vue

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
<template>
22
<Layout>
3-
<div slot="content" class="item1">
3+
<div
4+
slot="content"
5+
class="item1">
46
<div class="text">
5-
<el-button type="primary" @click="handleOpen">全部打开</el-button>
7+
<el-button
8+
type="primary"
9+
@click="handleOpen">全部打开</el-button>
610
</div>
711
</div>
812
</Layout>
913
</template>
1014

1115
<script>
12-
import Layout from 'components/layout1';
13-
import Modal from 'components/modal';
16+
import Layout from 'components/layout1';
17+
import Modal from 'components/modal';
1418
15-
export default {
16-
components: {
17-
Layout
18-
},
19-
methods: {
20-
handleOpen() {
21-
Modal.confirmModal('确定打开所有设备吗?');
22-
}
19+
export default {
20+
components: {
21+
Layout
22+
},
23+
methods: {
24+
handleOpen() {
25+
Modal.confirmModal('确定打开所有设备吗?');
2326
}
24-
};
27+
}
28+
};
2529
</script>
2630

2731
<style lang="scss" scoped>

src/pages/item3/echarts/line.vue

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<template>
2+
<div id="lineChart" style="width: 100%; height: 100%" />
3+
</template>
4+
5+
<script>
6+
import echarts from 'echarts';
7+
8+
let LineChart = echarts;
9+
export default {
10+
name: 'Lines',
11+
props: {
12+
param: {
13+
type: Array,
14+
required: true
15+
}
16+
},
17+
watch: {
18+
param() {
19+
if (this.param && this.param.length) {
20+
this.initLines();
21+
}
22+
}
23+
},
24+
mounted() {
25+
LineChart = echarts.init(document.getElementById('lineChart'));
26+
if (this.param && this.param.length) {
27+
this.initLines();
28+
}
29+
},
30+
methods: {
31+
initLines() {
32+
const successrate = [];
33+
const maxsuccessimagerate = [];
34+
const maxsuccessregionrate = [];
35+
const maxfailimagerate = [];
36+
const maxfailregionrate = [];
37+
const counttime = [];
38+
this.param.forEach((value) => {
39+
successrate.push(value.successrate);
40+
maxsuccessimagerate.push(value.maxsuccessimagerate);
41+
maxsuccessregionrate.push(value.maxsuccessregionrate);
42+
maxfailimagerate.push(value.maxfailimagerate);
43+
maxfailregionrate.push(value.maxfailregionrate);
44+
counttime.push(value.counttime);
45+
});
46+
47+
const option = {
48+
title: {
49+
text: '堆叠区域图',
50+
x: 'center'
51+
},
52+
color: ['#dd5820', '#007ac2', '#81c267', '#facc41'],
53+
tooltip: {
54+
trigger: 'axis'
55+
},
56+
legend: {
57+
top: '30',
58+
data: ['测试一', '测试二', '测试三', '测试四', '测试五']
59+
},
60+
grid: {
61+
left: '3%',
62+
right: '4%',
63+
bottom: '3%',
64+
containLabel: true
65+
},
66+
toolbox: {
67+
right: 60,
68+
feature: {
69+
saveAsImage: {}
70+
}
71+
},
72+
xAxis: [
73+
{
74+
type: 'category',
75+
boundaryGap: false,
76+
data: counttime
77+
}
78+
],
79+
yAxis: [
80+
{
81+
type: 'value',
82+
axisLabel: {
83+
textStyle: {
84+
color: '#5a6c77',
85+
fontSize: '12',
86+
extraCssText: 'line-height:30px'
87+
}
88+
}
89+
}
90+
],
91+
series: [
92+
{
93+
name: '测试一',
94+
type: 'line',
95+
data: successrate
96+
}, {
97+
name: '测试二',
98+
type: 'line',
99+
data: maxsuccessimagerate
100+
}, {
101+
name: '测试三',
102+
type: 'line',
103+
data: maxsuccessregionrate
104+
}, {
105+
name: '测试四',
106+
type: 'line',
107+
data: maxfailimagerate
108+
}, {
109+
name: '测试五',
110+
type: 'line',
111+
data: maxfailregionrate
112+
}
113+
]
114+
};
115+
116+
LineChart.setOption(option);
117+
}
118+
}
119+
};
120+
</script>

src/pages/item3/option1.vue

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,64 @@
11
<template>
22
<layout>
33
<div slot="content">
4-
option1
4+
<el-tabs v-model="activeName" @tab-click="handleClick">
5+
<el-tab-pane label="用户管理" name="first">
6+
<div class="tabLine">
7+
<Lines :param="lineData" />
8+
</div>
9+
</el-tab-pane>
10+
<el-tab-pane label="配置管理" name="second">配置管理</el-tab-pane>
11+
<el-tab-pane label="角色管理" name="third">角色管理</el-tab-pane>
12+
<el-tab-pane label="定时任务补偿" name="fourth">定时任务补偿</el-tab-pane>
13+
</el-tabs>
514
</div>
615
</layout>
716
</template>
817

918
<script>
10-
import Layout from 'components/layout'
19+
import Layout from 'components/layout';
20+
import Axios from 'util/axios';
21+
import Lines from './echarts/line';
1122
12-
export default {
13-
components: {
14-
Layout
23+
const urlLine = 'claa/linelist';
24+
export default {
25+
components: {
26+
Layout,
27+
Lines
28+
},
29+
data() {
30+
return {
31+
activeName: 'first',
32+
lineData: []
33+
};
34+
},
35+
mounted() {
36+
this.doQueryLine();
37+
},
38+
methods: {
39+
handleClick(tab, event) {
40+
console.log(tab, event);
41+
},
42+
doQueryLine() {
43+
const that = this;
44+
const param = {
45+
loadingFlag: true,
46+
url: urlLine,
47+
method: 'GET',
48+
data: {},
49+
successFn(data) {
50+
that.lineData = data.list;
51+
}
52+
};
53+
Axios.fetch(param);
1554
}
1655
}
17-
</script>
56+
};
57+
</script>
58+
59+
<style lang="scss" scoped>
60+
.tabLine{
61+
height:400px;
62+
margin-top: 20px;
63+
}
64+
</style>

0 commit comments

Comments
 (0)