日志-2021-8-18
RtZhao

ECharts

Apache ECharts

ECharts + Json

data.json

1
2
3
4
5
6
7
8
9
10
11
12
{
"text":"ECharts ajax示例",
"legend": "销量",
"xAxis-":["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"],
"series": [
{
"name": "销量",
"type": "bar",
"data": [5, 20, 36, 10, 10, 20]
}
]
}

Echarts-Json.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 lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>

</head>
<body>
<div id="main" style="width: 600px;height: 400px;margin: 10% auto"></div>
<script type="application/json" src="data.json"></script>
<script type="application/javascript" src="res/js/jQuery/jquery.js"></script>
<script type="application/javascript" src="res/js/echarts/echarts.min.js"></script>

<script>
$(document).ready(function (){
const myChart = echarts.init(document.getElementById('main'));

const option = {
title: {
text:''
},
tooltip: {},
legend: {
data: []
},
xAxis: {
data: []
},
yAxis: {},
series: [{
name: '',
type: '',
data: []
}
]
};

myChart.setOption(option);

$.getJSON('data.json').done(function (data){
myChart.setOption({
title: {
text:data.text
},
tooltip: {},
legend: {
data: data.legend
},
xAxis: {
data: data.xAxis
},
yAxis: {},
series: [{
name: data.series[0].name,
type: data.series[0].type,
data: data.series[0].data
}
]
})
})

})
</script>

</body>
</html>

目录结构

image-20210818183731728

  • 本文标题:日志-2021-8-18
  • 本文作者:RtZhao
  • 创建时间:2021-08-18 08:38:59
  • 本文链接:https://www.rtzhao.site/2021/08/18/日志-2021-8-18/
  • 版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
 评论