-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patheCharts-test.html
201 lines (169 loc) · 5.31 KB
/
eCharts-test.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
<!doctype html>
<html lang="en">
<head>
<title>COVID-19 Coronavirus Disease Spread Analysis in German Regions and the World</title>
<meta charset="utf-8">
<meta name="author" content="Dr. Torben Menke">
<!-- <link rel="stylesheet" href="/style.css" /> -->
<link rel="stylesheet" href="style-covid.css" />
<!-- Polyfiles for IE, suggested by Tabulator : http://tabulator.info/docs/4.6/browsers#ie -->
<script src="./js/tabulator-polyfill.min.js"></script>
<script src="./js/tabulator-fetch.umd.js"></script>
<!-- eCharts -->
<script src="./js/echarts-4.7.0-en.min.js"></script>
<script src="./js/jquery-3.5.0.min.js"></script>
<script src="./js/myHelper.js"></script>
<!-- <script src="https://cdn.bootcss.com/echarts/4.1.0.rc2/echarts-en.min.js"></script> -->
<style>
.echart-wrap {
display: inline-block;
width: 700px;
height: 700px;
overflow: scroll;
border: 1px solid black;
}
</style>
</head>
<body>
<div class="echart-latest-data-wrapper">
<div id="canvas1" style="height: 2000px">
</div>
</div>
<script>
// // array of promises for async fetching, used for eCharts plots
// const promises = [];
// fetch mapping_landkreis_ID_name.json reference data like code and continent
var array_countries_latest = {};
function fetch_countries_latest(array_countries_latest) {
const url =
"https://entorb.net/COVID-19-coronavirus/data/int/countries-latest-all.json";
return $.getJSON(url, function (data) {
console.log("success: array_countries_latest");
})
.done(function (data) {
console.log("done: array_countries_latest");
$.each(data, function (key, val) {
code = data[key]['Code'];
array_countries_latest[code] = val;
delete array_countries_latest[code]['Code'];
});
// console.log(array_countries_latest);
})
.fail(function () {
console.log("fail: array_countries_latest");
});
}
promises.push(fetch_countries_latest(array_countries_latest));
var data_names = []; //array_countries_latest.keys();
var data_values = [];
var countryLatestData = {};
// Wait for all async promises to be done (all data is fetched)
Promise.all(promises).then(function () {
// console.log(array_countries_latest);
create_latest_data_plot('canvas1', 'DoublingTime_Cases_Last_Week_Per_100000', 'Cases_Last_Week_Per_Million')
//setDataToPlot('DoublingTime_Cases_Last_Week_Per_100000', 'DESC')
});
function create_latest_data_plot(eChartsObjectID, property, property_for_color) {
let ordering = 'ASC';
let sortmap = [];
const codes_ordered = [];
var data_names = [];
var data_values = [];
var data_values_property_for_color = [];
var data_set = [];
var max_property_for_color = 0;
if (property == 'DoublingTime_Cases_Last_Week_Per_100000') {
ordering = 'DESC';
}
for (const [key, values] of Object.entries(array_countries_latest)) {
if (property in values) {
value = values[property];
sortmap.push([key, value]);
}
}
sortmap.sort(function (a, b) {
return a[1] - b[1];
});
for (let i = 0; i < sortmap.length; i++) {
codes_ordered.push(sortmap[i][0]);
}
if (ordering == 'DESC') {
codes_ordered.reverse();
}
for (let i = 0; i < codes_ordered.length; i++) {
name = array_countries_latest[codes_ordered[i]]['Country'];
value = array_countries_latest[codes_ordered[i]][property];
value_property_for_color = array_countries_latest[codes_ordered[i]][property_for_color];
// data_names.push(name);
// data_values.push(value);
if (value_property_for_color > max_property_for_color) {
max_property_for_color = value_property_for_color;
}
// data_values.push([value, array_countries_latest[codes_ordered[i]]['Cases_Per_Million']]);
data_set.push([name, value, value_property_for_color]);
// data_values_cases_total.push(array_countries_latest[codes_ordered[i]]['Cases_Per_Million']);
}
console.log(data_values);
option = {
title: {
// text: "COVID-19: Landkreisvergleich 7-Tages-Neuinfektionen",
text: "COVID-19: " + capitalize_words(property, "_"),
left: 'center',
subtext: "by Torben https://entorb.net based on JHU data",
sublink: "https://entorb.net/COVID-19-coronavirus/",
},
yAxis: {
type: 'category',
// data: data_names,
},
xAxis: {
type: 'value',
position: 'top',
},
dataset: {
source: data_set,
},
series: [{
// data: data_values,
datasetIndex: 0,
type: 'bar'
}],
tooltip: {
trigger: 'item', // item or axis
// formatter: {
// // params: value[params.encode.y[0]]
// }
},
toolbox: {
show: true,
showTitle: true,
feature: {
saveAsImage: {},
},
}, grid: {
containLabel: false,
left: 200,
bottom: 20,
top: 90,
right: 20,
},
visualMap: {
dimension: 2,
min: 0,
max: max_property_for_color,
text: [max_property_for_color, 0],
// top: '60',
show: false,
// dataValue corresponding to the two handles.
}
};
// fine tuning
if (property == 'DoublingTime_Cases_Last_Week_Per_100000') {
option.title.text = 'COVID-19: New Cases Doubling Time (days)'
}
let echartsObj = echarts.init(document.getElementById(eChartsObjectID));
echartsObj.setOption(option)
}
</script>
</body>
</html>