-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
40 lines (30 loc) · 1.27 KB
/
script.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
$(document).ready(function() {
var dataURL = "https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/GDP-data.json";
$.getJSON(dataURL).success(function(dataJSON) {
var data = dataJSON.data;
var canvas = d3.select("body").append("svg")
.attr("width", 1200)
.attr("height", 450)
.append("g")
.attr("transform", "translate(50, 45)");
var bars = canvas.selectAll("rect")
.data(data)
.enter()
.append("rect")
.attr("width", 3)
.attr("height", function(d, i) {
return d[1]/50;
})
.attr("x", function(d, i) { return i * 4; })
.attr("y", 0)
.attr("fill", "teal")
.on("mouseover", function(d, i) {
d3.select(this).attr("fill", "#f44336");
$("h3").text(d[0] + " - " +"$ " +d[1]+ " Billion")
})
.on("mouseout", function(d) {
d3.select(this).attr("fill", "teal");
$("h3").text("Gross Domestic Population")
});
}); //json
}); //ready function