-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task_2.4.js
48 lines (43 loc) · 1.11 KB
/
Task_2.4.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
function init(){
var w = 500;
var h = 100;
var barPadding = 2;
d3.csv("Task_2.4_data.csv").then(function(data){
console.log(data);
dataset = data;
barChart(dataset)
})
var svg = d3.select("#chart")
.append("svg")
.attr("width", w)
.attr("height", h);
function barChart(){
svg.selectAll("rect")
.data(dataset)
.enter()
.append("rect")
.style("fill", d =>{
console.log("d = " + d.datasets);
if(d.datasets <= 40){
return "#ADD8E6"
}else if(d.datasets >= 80){
return "#00008B";
}else{
return "#0000FF"
}
})
.attr("x", function(d,i){
return i*(w/dataset.length)
})
.attr("y", function (d){
return h-(d.datasets)
})
.attr("width", function (d){
return w/dataset.length - barPadding
})
.attr("height", function (d){
return d.datasets
});
}
}
window.onload = init;