-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjosephine_scratch_2.html
More file actions
executable file
·67 lines (49 loc) · 1.25 KB
/
Copy pathjosephine_scratch_2.html
File metadata and controls
executable file
·67 lines (49 loc) · 1.25 KB
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
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.chart rect {
fill: steelblue;
}
.chart text {
fill: white;
font: 10px sans-serif;
text-anchor: end;
}
</style>
<script src="https://d3js.org/d3.v4.min.js"></script>
<button>hi</button>
<svg class="chart"></svg>
<script>
// var data = [
// {'name':'a','value':4},
// {'name':'b','value':8},
// {'name':'c','value':15},
// {'name':'d','value':16},
// {'name':'e','value':23},
// {'name':'f','value':42}
// ];
var data = [4, 8, 15, 16, 23, 42];
var width = 420,
barHeight = 20;
var x = d3.scaleLinear()
.domain([0, d3.max(data)])
.range([0, width]);
var chart = d3.select(".chart")
.attr("width", width)
.attr("height", barHeight * data.length);
function updateGraph(bar) {
bar.append("rect")
.attr("width", x)
.attr("height", barHeight - 1);
bar.append("text")
.attr("x", function(d) { return x(d) - 3; })
.attr("y", barHeight / 2)
.attr("dy", ".35em")
.text(function(d) { return d; });
}
var bar = chart.selectAll("g").data(data).enter().append("g")
.attr("transform", function(d, i) { return "translate(0," + i * barHeight + ")"; });
updateGraph(bar)
var newData = [14, 3, 10, 10, 13, 24];
updateGraph(bar.selectAll("g").data(newData).transition())
</script>