-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
76 lines (60 loc) · 2.07 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Curso d3js</title>
<script src="https://d3js.org/d3.v7.min.js"></script>
<style>
svg {
background-color: #ccc;
}
</style>
</head>
<body>
<script>
var dataArray = ["30", "15", "50", "70"];
var width = 500;
var height = 500;
const canvas = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
// const circle = canvas.selectAll("cirlce")
// .data(dataArray)
// .enter()
// .append("circle")
// .attr("cx", function (d,i){return d*5;})
// .attr("cy",50)
// .attr("r",30)
// .attr("fill","red");
const widthScale = d3.scaleLinear()
.domain([0, 80])
.range([0, width]);
const colorScale = d3.scaleLinear()
.domain([0, 80])
.range(["red", "blue"]);
const rects = canvas.selectAll("rect")
.data(dataArray)
.enter()
.append("rect")
.attr("width", 50)
.attr("height", 50)
//.attr("fill", function (d) { return colorScale(d); })
.attr("fill", "#000")
.attr("y", 0);
// console.log(rect);
// d3.selectAll("rect").transition(rects)
// .duration(1500)
// .style("fill", "red");
rects.transition()
.duration(1000)
.attr("y", function (d,i){return i*100})
.transition()
.duration(1500)
.attr("width", function (d) { return widthScale(d); })
.attr("fill", function (d) { return colorScale(d); });
</script>
</body>
</html>