-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstockChart.html
79 lines (70 loc) · 1.67 KB
/
stockChart.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
<!DOCTYPE html>
<html>
<head>
<title>Stock Chart</title>
<script type="text/javascript" src="/static/js/lib/d3.js"></script>
<style type="text/css">
path {
stroke: steelblue;
stroke-width: 2;
fill: none;
}
line {
stroke: black;
}
text {
font-family: Arial;
font-size: 9pt;
}
</style>
</head>
<body>
<script type="text/javascript">
var x=d3.scale.linear().domain([0,10]).range([0,400]),
y=d3.scale.linear().domain([0,1]).range([0,50]),
groupHeight=60,
topMargin=100;
var data=[];
d3.range(10).forEach(function(d){data.push(Math.random())});
var interpolations = [
"linear",
"step-before",
"step-after",
"basis",
"basis-closed",
"cardinal",
"cardinal-closed"];
function getLine(interpolation){
return d3.svg.line().x(function(d,i){
return x(i);
}).y(function(d){
return y(d);
}).interpolate(interpolation);
}
var vis=d3.select("body")
.append("svg:svg")
.attr("class","vis")
.attr("width",window.width)
.attr("height",window.height);
var lg=vis.selectAll(".lineGroup")
.data(interpolations)
.enter().append("svg:g")
.attr("class","lineGroup")
.attr("transform",function(d,i){
return "translate(100," + (topMargin + i * groupHeight) + ")" ;
}).each(drawLine);
function drawLine(p,j) {
d3.select(this)
.selectAll(".lineGroup")
.data(data)
.enter().append("svg:path")
.attr("d", getLine(p)(data))
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 3)
//.attr("stroke-dasharray", "15 5")
}
console.log(data);
</script>
</body>
</html>