-
Notifications
You must be signed in to change notification settings - Fork 0
/
bar1.html
82 lines (70 loc) · 2.14 KB
/
bar1.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> The Banal Bars</title>
<script type="text/javascript" src="d3.js"></script>
<style type="text/css">
p{
padding: 10px}
</style>
</head>
<body>
<p>
The ubiquitos bars charts, that's it! Still, here, fully handmade (SVG and data based).
<br>
And as promised, the colors are no longer <em>kunstwollen</em> based but linked to the data:
<br>
precisely, the first two of RGB are fix and the number of B (blue) is determined by the data.
<br>
In this way, the blue shadow varies regarding to the data (number).
<br>
The things are simple, while there is a simple list of data: to one position corresponds one value.
<br>
Next step: introducing two (or more) values.
</p>
<script type="text/javascript">
var w = 500;
var h = 400;
var barPadding = 1;
var dataset = [7, 4, 10, 41, 15, 12, 20, 25, 30, 47, 60, 90, 5];
var svg = d3.select("body")
.append('svg')
.attr("width", w)
.attr("height", h);
svg.selectAll("rect")
.data(dataset)
.enter()
.append("rect")
.attr("x", function(d,i){
return i*(w/dataset.length);
})
.attr("y", function(d){
return h - d*4;
})
.attr("width", w/dataset.length - barPadding)
.attr("height", function(d){
return d * 4;
})
.style("fill", function(d){
return "rgb(10, 10, " Math.round(d*5) ")";
})
svg.selectAll("text")
.data(dataset)
.enter()
.append("text")
.text(function(d){
return d;
})
.attr("x", function(d,i){
return i*(w/dataset.length) 15 ;
})
.attr("y", function(d){
return h - d*4 15;
})
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("fill", "white");
</script>
</body>
</html>