forked from jtr13/D3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EDAV8_1_linegen.html
executable file
·48 lines (39 loc) · 1.05 KB
/
EDAV8_1_linegen.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Line generator</title>
<script src="https://d3js.org/d3.v4.min.js"></script>
<style type ="text/css">
.linestyle {
fill: none;
stroke: teal;
stroke-width: 5px;
}
</style>
</head>
<body>
<script>
var w = 500;
var h = 400;
var svg = d3.select("body").append("svg")
.attr("width", w).attr("height", h);
var dataset = [ [0, 60], [1, 43], [2, 43], [3, 56],
[4, 45], [5, 62], [6, 49] ];
var xScale = d3.scaleBand()
.domain(d3.range(dataset.length))
.range([0, w]);
var yScale = d3.scaleLinear()
.domain([d3.min(dataset, d => d[1]) - 20,
d3.max(dataset, d => d[1]) + 20])
.range([h, 0]);
var mylinegen = d3.line()
.x(d => xScale(d[0]))
.y(d => yScale(d[1]));
svg.append("path")
.datum(dataset)
.attr("d", mylinegen)
.attr("class", "linestyle");
</script>
</body>
</html>