index.html
6.86 KB
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
<html>
<head>
<meta charset="utf-8">
<script crossorigin="anonymous" integrity="sha384-RPqk+IZGGuMAN/gBBbPKRtfXRISl/vFqiT13cXlm2vHZtd+xZ7ugm9sDxXDb2Ylk" src="https://lib.baomitu.com/echarts/4.6.0/echarts.min.js"></script>
<script src="https://s2.pstatp.com/cdn/expire-1-M/jquery/3.4.0/jquery.min.js" type="application/javascript"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<style>
h1 {
line-height: 60px;
height: 60px;
background: #146402;
text-align: center;
font-weight: bold;
color: #eee;
font-size: 14px;
}
.chart {
height: 600px;
}
</style>
<div id="main" class="chart"></div>
<script>
let chart = echarts.init(document.getElementById('main'));
const params = new URLSearchParams(location.href.split('?')[1]);
let province = params.get('province') || '上海';
let sizeValue = '57%';
let symbolSize = 2.5;
$.getJSON('c/info/stat', {province:province}, function(result) {
if (!result || result.ret !== 'OK') {
console.error('查询数据错误', result);
return;
}
let [content0, content1] = result.content;
content1 = content1 || {}
let data = {
today: content0.days.map(function(s){return s.substr(6)}),
increase: content1.increase,
confirmed_count: content1.confirmed_counts,
increase_sum: content0.increase,
confirmed_sum: content0.confirmed_counts
};
let option = {
legend: {},
tooltip: {},
toolbox: {
left: 'center',
feature: {
dataZoom: {}
}
},
grid: [
{right: sizeValue, bottom: sizeValue},
{left: sizeValue, bottom: sizeValue},
{right: sizeValue, top: sizeValue},
{left: sizeValue, top: sizeValue}
],
dataset: {
// 这里指定了维度名的顺序,从而可以利用默认的维度到坐标轴的映射。
// 如果不指定 dimensions,也可以通过指定 series.encode 完成映射,参见后文。
dimensions: [
{name: 'today', type:'ordinal', displayName: '日期'},
{name: 'increase', type:'number', displayName: province+'新增人数'},
{name: 'confirmed_count', type:'number', displayName: province+'确诊人数'},
{name: 'increase_sum', type:'number', displayName: '全国新增人数'},
{name: 'confirmed_sum', type:'number', displayName: '全国确诊人数'}
],
source: data
},
xAxis: [
{type: 'category', gridIndex: 0, name: '日期', axisLabel: {rotate: 50, interval: 5}},
{type: 'category', gridIndex: 1, name: '日期', axisLabel: {rotate: 50, interval: 5}},
{type: 'category', gridIndex: 2, name: '日期', axisLabel: {rotate: 50, interval: 5}},
{type: 'category', gridIndex: 3, name: '日期', axisLabel: {rotate: 50, interval: 5}, axisPointer:{show: true, type: 'line'}}
],
yAxis: [
{type: 'value', gridIndex: 0, name: province+'新增人数'},
{type: 'value', gridIndex: 1, name: '全国新增人数', axisPointer:{show: true, type: 'line'}},
{type: 'value', gridIndex: 2, name: province+'确诊人数'},
{type: 'value', gridIndex: 3, name: '全国确诊人数'}
],
series: [
{
type: 'bar',
symbolSize: symbolSize,
xAxisIndex: 0,
yAxisIndex: 0,
encode: {
x: 'today',
y: 'increase',
tooltip: [0, 1, 2, 3, 4]
},
tooltip: {
formatter: function (params,ticket,callback) {
if (params.componentType === 'legend') {
return params.name;
}
// console.info('param ==>', params, )
let res = '自定义详情: ';
for (let [i, dname] of params.dimensionNames.entries()) {
res += '<br/>' + dname + ' : ' + params.data[i];
}
setTimeout(function (){
// 仅为了模拟异步回调
callback(ticket, res);
}, 300);
return 'loading';
}
}
},
{
type: 'line',
sampling: 'average',
itemStyle: {
color: '#2d85cb'
},
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: '#90bcc2'
}, {
offset: 1,
color: '#3598dc'
}])
},
symbolSize: symbolSize,
xAxisIndex: 1,
yAxisIndex: 1,
smooth: true,
encode: {
x: 'today',
y: 'increase_sum',
tooltip: [0, 3, 4]
}
},
{
type: 'bar',
symbolSize: symbolSize,
seriesName: [0,2],
xAxisIndex: 2,
yAxisIndex: 2,
encode: {
x: 'today',
y: ['confirmed_count'],
tooltip: [0, 1, 2, 3, 4]
}
},
{
type: 'line',
areaStyle: {},
symbolSize: symbolSize,
xAxisIndex: 3,
yAxisIndex: 3,
smooth: true,
encode: {
x: 'today',
y: 'confirmed_sum',
tooltip: [0, 3, 4]
}
}
]
};
chart.setOption(option);
})
chart.on('click', function (params) {
console.log(params);
});
window.onresize = chart.resize;
</script>
</body>
</html>