-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdcHeroinDeaths.js
80 lines (67 loc) · 1.77 KB
/
cdcHeroinDeaths.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
console.log('cdcHeroinDeaths.js loaded');
CDC={};
CDC.loadData=function(){
$.getJSON('https://evergreen.data.socrata.com/resource/d26f-b5yf.json')
.then(function(x){
CDC.data = x;
console.log('done loading data');
$('<p>'+'just loaded '+x.length+' rows</p>').appendTo(document.body);
})
}
//CDC.loadData();
Plotly.d3.json('https://evergreen.data.socrata.com/resource/d26f-b5yf.json',
function(items){
var index;
var year= [];
var y1 = [];
var y2 = [];
for (index = 0; index < items.length; index++) {
year.push(items[index].year);
y1.push(items[index].heroin_addiction_per_1_000_people);
y2.push(items[index].heroin_related_overdose_deaths_per_100_000_people);
}
var trace1 = {
x: year,
y: y1,
name: 'Heroin Addiction (per 1,000 people)',
marker: {color: 'rgb(55, 83, 109)'},
type: 'bar'
};
var trace2 = {
x: year,
y: y2,
name: 'Heroin Related Overdose Deaths (per 100,000 people)',
marker: {color: 'rgb(26, 118, 255)'},
type: 'bar'
};
var data = [trace1, trace2];
var layout = {
title: 'US Heroin Addiction & Deaths 2002-2013',
xaxis: {tickfont: {
size: 14,
color: 'rgb(107, 107, 107)'
}},
yaxis: {
title: '',
titlefont: {
size: 16,
color: 'rgb(107, 107, 107)'
},
tickfont: {
size: 14,
color: 'rgb(107, 107, 107)'
}
},
legend: {
x: 0,
y: 1.0,
bgcolor: 'rgba(255, 255, 255, 0)',
bordercolor: 'rgba(255, 255, 255, 0)'
},
barmode: 'group',
bargap: 0.15,
bargroupgap: 0.1
};
Plotly.newPlot('myDiv', data, layout);
}
);