异步加载数据

这是图片

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
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../echarts.js"></script>
<script src="../jquery/jquery.js"></script>
<style>
.box {
width: 800px;
height: 600px;
background-color: aqua;
}
</style>
</head>
<body>
<div class="box"></div>
<script>
let box = document.querySelector(".box")
let myChart = echarts.init(box)
let option ={
title:{
text:"标题",
subtext:"副标题",
left:"center"
},
toolbox:{
show:true,
feature:{
saveAsImage:{
show:true
}
}
},
tooltip:{
trigger:"item",
formatter:"{a}</br>{b}:{c}({d}%)"
},
legend:{
x:1,
data:[],
},
calculable: true,
series:[
{
data:[

]
}
]
}
myChart.setOption(option)
myChart.showLoading({
text:"请你稍稍休息片刻,loading data...",

})
let showData = []
let legent = []
setTimeout(function(){
$.get("data_pie.json").done(function(data){
showData = data.data_pie
console.log(data.data_pie.length)
for(let i = 0;i<data.data_pie.length;i++){
console.log(data.data_pie[i].name)
legent.push(data.data_pie[i].name)
}
option.legend.data=legent
console.log(showData)
myChart.setOption(option)
myChart.setOption({
series:[
{
name:'访问来源',
type: 'pie',
data:showData
}
]
})
})
myChart.hideLoading()
}, 3000)
</script>
</body>
</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
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<script type="text/javascript" src='echarts.js'></script>
</head>

<body>
<div id="main" style="height: 800px"></div>
<script type="text/javascript">

var myChart = echarts.init(document.getElementById("main"));
var option = {
backgroundColor: 'rgba(128, 128, 128, 0.1)',
title: { text: '22级电子商务学院各专业招生情况', left: 'center', top: 9 },
legend:{left:'70%',top:100,orient:'vertical',},
tooltip: {
trigger: 'item', show: true,
formatter: "{a} <br/>{b} : {c}"
},

series: [
{
name: '招生专业比例', type: 'pie',
data: [
{name:'软件技术',value:180},
{name:'大数据',value:85},
{name:'计算机网络',value:88},
{name:'电子商务',value:350},
{name:'软件工程',value:165},
]
},

]
};

myChart.setOption(option);
myChart.on("click",function(params){
alert(params.name+"的专业招生比例为:"+params.data.value+"\n"
+"--seriesName:"+params.seriesName+"\n"
+"--color:"+params.color+"\n"
+"--seriesType:"+params.seriesType
)
if(params.name=="软件技术"){
window.open("https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=%E8%BD%AF%E4%BB%B6%E6%8A%80%E6%9C%AF&fenlei=256&oq=%25E8%25B6%2585%25E6%2598%259F&rsv_pq=a72f8e3e000fe0bb&rsv_t=550fLLawVAjY9HKEF5eFvZfVRpFSLlQFxE%2BGpxtkqzwKIA%2FemhOInmppPK0&rqlang=cn&rsv_enter=1&rsv_dl=tb&rsv_sug3=3&rsv_sug1=3&rsv_sug7=100&rsv_sug2=0&rsv_btype=t&inputT=4628&rsv_sug4=5366")
}
console.log(params)
})
window.addEventListener("resize",function(){
myChart.resize()
})
myChart.on("legendselectchanged",function(params){

if(params.selected[params.name]){
console.log(params.name+"被你选中了")
}else{
console.log(params.name+"被你取消选中了")
}
})

</script>
</body>

</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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Document</title>

<script src="echarts.js"></script>

<script src="theme/dark.js"></script>

<script src="theme/infographic.js"></script>

<script src="theme/macarons.js"></script>

<script src="theme/shine.js"></script>

<script src="theme/vintage.js"></script>

<style>

.box{

height: 600px;

width: 1200px;

}

</style>

</head>

<body>

<h3>切换主题</h3>

<select class="sel">

<option value="dark">dark</option>

<option value="infographic">infographic</option>

<option value="macarons">macarons</option>

<option value="shine">shine</option>

<option value="vintage">vintage</option>

</select>

<div class="box"></div>

<script>

let box = document.querySelector(".box")

let myChart = echarts.init(box,"dark")

let option = {

title: {

text: 'Stacked Area Chart'

},

tooltip: {

trigger: 'axis',

axisPointer: {

type: 'cross',

label: {

backgroundColor: '#6a7985'

}

}

},

legend: {

data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']

},

toolbox: {

feature: {

saveAsImage: {}

}

},

grid: {

left: '3%',

right: '4%',

bottom: '3%',

containLabel: true

},

xAxis: [

{

type: 'category',

boundaryGap: false,

data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']

}

],

yAxis: [

{

type: 'value'

}

],

series: [

{

name: 'Email',

type: 'line',

stack: 'Total',

areaStyle: {},

emphasis: {

focus: 'series'

},

data: [120, 132, 101, 134, 90, 230, 210]

},

{

name: 'Union Ads',

type: 'line',

stack: 'Total',

areaStyle: {},

emphasis: {

focus: 'series'

},

data: [220, 182, 191, 234, 290, 330, 310]

},

{

name: 'Video Ads',

type: 'line',

stack: 'Total',

areaStyle: {},

emphasis: {

focus: 'series'

},

data: [150, 232, 201, 154, 190, 330, 410]

},

{

name: 'Direct',

type: 'line',

stack: 'Total',

areaStyle: {},

emphasis: {

focus: 'series'

},

data: [320, 332, 301, 334, 390, 330, 320]
},
{
name: 'Search Engine',
type: 'line',
stack: 'Total',
label: {
show: true,
position: 'top'
},
areaStyle: {},
emphasis: {
focus: 'series'
},
data: [820, 932, 901, 934, 1290, 1330, 1320]
}
]
};

myChart.setOption(option)

const sel = document.querySelector(".sel")

sel.addEventListener("change",function(){

myChart.dispose()

let s = this.value

console.log(s)

myChart = echarts.init(box,s)

myChart.setOption(option)

})

</script>

</body>

</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
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="echarts.js"></script>
</head>
<style>
.box{
height: 300px;
width: 600px;
}
.box2{
height: 300px;
width: 600px;
}
</style>
<body>
<div class="box"></div>
<div class="box2"></div>
</body>
<script>
let box = document.querySelector(".box")
let box2 = document.querySelector(".box2")
let myChart = echarts.init(box)
let myChart2 = echarts.init(box2)
let option={
title:{
text:"标题一",
subtext:"副标题"
},
tooltip:{
trigger: 'item'
},
xAxis:{
type:'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis:{
type:'value',
},
series:[
{
type:'bar',
name:'销售',
data:[320, 302, 301, 334, 390, 330, 320],
label:{
show:true
}
}
]
}
let option2={
title:{
text:'饼图',
subtext:"副标题",
left:'center'
},
tooltip:{
trigger:'item'
},
series:[
{
type:'pie',
name:'Access From',
radius:["45%","75%"],
center: ['58%', '55%'],
data:[
{value: 60, name: 'Mon'},
{value:40,name:'Tue'},
{value:30,name:'Wed'},
{value:80,name:'Thu'},
{value:90,name:'Fri'},
{value:34,name:'Sat'},
{value:65,name:'Sun'}
]
}

]
}
myChart.setOption(option)
myChart2.setOption(option2)
echarts.connect([myChart,myChart2])
</script>
</html>