可视化_echarts

echarts.init接口方法

名称 参数 描述
{ECharts} init {dom} dom, {string | Object =} theme 初始化接口,返回ECharts实例,其中dom为图表所在节点,theme为可选的主题,内置主题(’macarons’, ‘infographic’)直接传入名称,自定义扩展主题可传入主题对象。如: var myCharts = echarts.init(document.getElementById(‘main’), ‘macarons’);

Demo的项目结构

image-20220930112545763.png

一眼望去应该都是知道各个目录的意思了吧

整体布局

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
<body>
<header id="header">
<h3 class="header-title">上市公司全景概览</h3>
<div class="header-info header-info-l">数据来源:上交所 &amp; 深交所</div>
<div class="header-info header-info-r">数据日期:<span id="nowDate"></span></div>
</header>

<footer id="footer"></footer>

<div id="container">
<div id="flexCon">
<div class="flex-row">
<div class="flex-cell flex-cell-l">
<div class="chart-wrapper">
<h3 class="chart-title">市价总值排行Top10</h3>
<div class="chart-div" id="rankChart">
<div class="chart-loader"><div class="loader"></div></div>
</div>
</div>
</div>
<div class="flex-cell flex-cell-c" style="padding-right:0;">
<div class="chart-wrapper">
<h3 class="chart-title">统计数据</h3>
<div class="chart-div chart-done">
<table class="data-t">
<tr>
<th><img src="img/icon-01.png" /></th>
<td>
<p><span id="listedCompany">0</span></p>
<p>上市公司数</p>
</td>
<th><img src="img/icon-02.png" /></th>
<td>
<p><span id="listedSecurity">0</span></p>
<p>上市证券数</p>
</td>
</tr>
<tr>
<th><img src="img/icon-03.png" /></th>
<td>
<p><span id="totalMarket">0</span></p>
<p>股票总市值(亿元)</p>
</td>
<th><img src="img/icon-04.png" /></th>
<td>
<p><span id="circulationMarket">0</span></p>
<p>股票流通市值(亿元)</p>
</td>
</tr>
<tr>
<th><img src="img/icon-05.png" /></th>
<td>
<p><span id="shRatio">0</span></p>
<p>上市平均市盈率</p>
</td>
<th><img src="img/icon-06.png" /></th>
<td>
<p><span id="szRatio">0</span></p>
<p>深市平均市盈率</p>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="flex-cell flex-cell-r" style="padding-left:0;">
<div class="chart-wrapper">
<h3 class="chart-title">上市公司L地域分布</h3>
<div class="chart-div" id="mapChart">
<div class="chart-loader"><div class="loader"></div></div>
</div>
</div>
</div>
</div>
<div class="flex-row">
<div class="flex-cell flex-cell-lc" style="padding-bottom:0;">
<div class="chart-wrapper">
<h3 class="chart-title">2018年月度股票情况及预测</h3>
<div class="chart-div" id="trendChart">
<div class="chart-loader"><div class="loader"></div></div>
</div>
</div>
</div>
<div class="flex-cell flex-cell-r" style="padding-bottom:0;">
<div class="chart-wrapper">
<h3 class="chart-title">CSRC行业分类</h3>
<div class="chart-div" id="csrcChart">
<div class="chart-loader"><div class="loader"></div></div>
</div>
</div>
</div>
</div>
</div>
</div>

获取当天日期

1
2
3
4
5
6
7
8
//获取当天日期
(function() {
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth()+1;
const day = now.getDate();
$("#nowDate").html(year+"年"+month+"月"+day+"日");
})();

其他板块的js

其实给我的感觉就是大差不差

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
const rankChart = echarts.init(document.getElementById("rankChart"), "shine");
const rankChartOpt = {
tooltip: {
trigger: "axis",
axisPointer: {
type: "shadow"
},
formatter: function(params) {
const param = params[0];
const marker = '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:#e6b600;"></span>';
const suffix = '<span style="margin-left:5px;font-size:12px;">亿元</span>';
return param.name + "<br />" +
marker + "排名:" + (param.dataIndex+1) + "<br />" +
marker + "市价总值:" + param.value + suffix;
}
},
grid: {
top: 10,
bottom: 10,
left: 60
},
xAxis: {
show: false,
type: "value"
},
yAxis: {
type: "category",
inverse: true,
axisLine: {show: false},
axisTick: {show: false},
axisLabel: {
fontSize: 12,
color: "#b0c2f9"
}
},
series: [{
name: "市价总值排行",
type: "bar",
barCategoryGap: "60%",
label: {
show: true,
position: "right",
fontSize: 12,
color: "#188df0",
emphasis: {
color: "#e6b600"
}
},
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0, 1, 1, 1,
[
{offset: 0, color: '#b0c2f9'},
{offset: 0.5, color: '#188df0'},
{offset: 1, color: '#185bff'}
]
)
},
emphasis: {
color: new echarts.graphic.LinearGradient(
0, 1, 1, 1,
[
{offset: 0, color: '#b0c2f9'},
{offset: 0.7, color: '#e6b600'},
{offset: 1, color: '#ceac09'}
]
)
}
}
}]
};
rankChart.setOption(rankChartOpt);
// 请求
$.ajax({
url: "data/ranking-list.json",
dataType: "json"
}).done(function() {
$("#rankChart").addClass("chart-done");
}).done(function(data) {
//console.log('Data: ', data);
const xData = [];
const yData = [];
for(let i in data) {
xData.push(data[i].market_capitalization);
yData.push(data[i].stock_name);
}
rankChart.setOption({
yAxis: {
data: yData
},
series: [{
name: "市价总值排行",
data: xData
}]
});
}).fail(function(jqXHR) {
console.log("Ajax Fail: ", jqXHR.status, jqXHR.statusText);
});

数据格式

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
[
{
"code": "A",
"industry": "农、林、牧、渔业",
"alias": "农林牧渔",
"sh_stock": 15,
"sz_stock": 26,
"stock": 41
},
{
"code": "B",
"industry": "采矿业",
"alias": "采矿业",
"sh_stock": 51,
"sz_stock": 26,
"stock": 77
},
{
"code": "C",
"industry": "制造业",
"alias": "制造业",
"sh_stock": 828,
"sz_stock": 1471,
"stock": 999
},
{
"code": "D",
"industry": "电力、热力、燃气及水生产和供应业",
"alias": "水电煤气",
"sh_stock": 66,
"sz_stock": 47,
"stock": 113
}]