-
Notifications
You must be signed in to change notification settings - Fork 0
/
图表自适应.html
73 lines (70 loc) · 1.91 KB
/
图表自适应.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ECharts 图标自适应</title>
<script src="../../vue.js"></script>
<script src="../../echarts.js"></script>
<script src="../../lodash.min.js"></script>
</head>
<body>
<div id="app">
<div id="main" style="width: 100%; height:400px;"></div>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
chart: null,
autoResize: true,
option: {
title: {
text: 'ECharts 入门示例'
},
tooltip: {},
legend: {
data: ['销量']
},
xAxis: {
data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
},
yAxis: {},
series: [
{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}
]
}
},
mounted() {
this.initChart()
if (this.autoResize) {
window.addEventListener('resize', this.resizeChart)
}
},
beforeDestroy() {
if (!this.chart) {
return
}
if (this.autoResize) {
window.removeEventListener('resize', this.resizeChart)
}
this.chart.dispose()
this.chart = null
},
methods: {
initChart() {
this.chart = echarts.init(document.getElementById('main'));
this.chart.setOption(this.option);
},
resizeChart: _.debounce(function () {
console.log('chart resize!')
this.chart.resize()
}, 100)
}
})
</script>
</body>
</html>