-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadCSV.html
71 lines (60 loc) · 1.75 KB
/
readCSV.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script src="https://d3js.org/d3.v4.min.js"></script>
<title>Document</title>
<style>
.line {
fill: none;
stroke-width: 3;
stroke: blue;
}
</style>
</head>
<body>
<script type="text/javascript">
var h = 600;
var w = 800;
var parseTime = d3.timeParse("%d-%b-%y")
var x = d3.scaleTime().range([0, w]);
var y = d3.scaleLinear().range([h, 0]);
var s = d3.select('#s');
var axisX = d3.svg.axis()
.scale(scaleX)
.ticks(10);
var axisY = d3.svg.axis()
.scale(scaleY)
.ticks(10);
s.append('path')
.attr({
'd': line(data),
'stroke': '#09c',
'fill': 'none'
});
s.append('g')
.call(axisX); //call axisX
s.append('g')
.call(axisY); //call axisY
d3.csv("./stocks.csv", function(data) {
data.forEach(function(d) {
d.date = parseTime(d.date);
d.close = +d.close;
});
x.domain(d3.extent(data, function(d) {
return d.date;
}))
y.domain([0, d3.max(data, function(d) {
return d.close;
})])
var ctrl = d3.select("body").append("svg").attr("width", w).attr("height", h)
var valueline = d3.line().x(function(d) {
return x(d.date);
}).y(function(d) {
return y(d.close);
})
ctrl.append('path').data([data]).attr("class", "line").attr("d", valueline);
});
</script>
</body>
</html>