forked from basse058/Project-3-Overdose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanychart.html
108 lines (96 loc) · 3.86 KB
/
anychart.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
<html>
<head>
<script src="https://cdn.anychart.com/geodata/latest/countries/united_states_of_america/united_states_of_america.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.15/proj4.js"></script>
<script src="https://cdn.anychart.com/releases/v8/js/anychart-base.min.js"></script>
<script src="https://cdn.anychart.com/releases/v8/js/anychart-ui.min.js"></script>
<script src="https://cdn.anychart.com/releases/v8/js/anychart-exports.min.js"></script>
<script src="https://cdn.anychart.com/releases/v8/js/anychart-map.min.js"></script>
<script src="https://cdn.anychart.com/releases/v8/js/anychart-data-adapter.min.js"></script>
<link href="https://cdn.anychart.com/releases/v8/css/anychart-ui.min.css" type="text/css" rel="stylesheet">
<link href="https://cdn.anychart.com/releases/v8/fonts/css/anychart-font.min.css" type="text/css" rel="stylesheet">
<style type="text/css">
html,
body,
#container {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
anychart.onDocumentReady(function () {
anychart.data.loadJsonFile(
'data.json',
function (data) {
var baseLink = 'https://en.wikipedia.org/wiki/';
// create map chart
var map = anychart.map();
var drugoverdosedeaths = data;
// settings for map chart
map
.padding([10, 0, 10, 10])
.geoData('anychart.maps.united_states_of_america')
.interactivity({ selectionMode: 'none' });
map
.title()
.enabled(true)
.useHtml(true)
.padding([10, 0, 10, 0])
.text(
'Drug Overdose Deaths by State between 2014-2019<br/>' +
'<span style="color:#929292; font-size: 12px;">' +
'(Hover cursor over state to see drug overdose death statistics by state)</span>'
);
// create choropleth series for map chart
var mapSeries = map.choropleth(anychart.data.set(drugoverdosedeaths));
mapSeries
.geoIdField('code_hasc')
.colorScale(
anychart.scales.linearColor('#f2f2f2', '#42a5f5', '#1976d2')
);
mapSeries
.hovered()
.fill(mapSeries.fill())
.stroke(mapSeries.stroke());
// custom text in tooltips for choropleth series for map chart
mapSeries
.tooltip()
.useHtml(true)
.titleFormat('{%Id}')
.format(function () {
var amount =
'<span style="color: #d9d9d9;">There are no drug overdose deaths in ' +
this.getData('name');
if (this.value > 0 && this.value === 1) {
amount =
'<span style="color: #d9d9d9;">' +
'<strong><span style="color: #fff;">' +
this.value +
' </span></strong>drug overdose deaths in ' +
this.getData('name') +
'</span><br/>Click to see more.';
} else if (this.value > 1) {
amount =
'<span style="color: #d9d9d9;">' +
'<strong><span style="color: #fff;">' +
this.value +
' </span></strong>drug overdose deaths in ' +
this.getData('name');
}
return amount;
});
// set container id for the chart
map.container('container');
// initiate chart drawing
map.draw();
}
);
});
</script>
</body>
</html>