Created
January 30, 2013 03:41
-
-
Save captainwz/4670423 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="http://d3js.org/d3.v2.js"></script> | |
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> | |
<script type="text/javascript"> | |
var random = d3.random.normal(0,0.3); | |
var data = d3.range(40).map(random); | |
function show(){ | |
d3.select("body") | |
.append("svg") | |
.attr("width",600) | |
.attr("height",400); | |
var x_scale = d3.scale.linear() | |
.range([60,580]) | |
.domain([-10,50]); | |
var y_scale = d3.scale.linear() | |
.range([280,20]) | |
.domain([-1,1]); | |
var x_axis=d3.svg.axis().scale(x_scale); | |
d3.select("svg") | |
.append("g") | |
.attr("class","x__axis") | |
.attr("transform","translate(0,280)") | |
.call(x_axis); | |
var y_axis=d3.svg.axis().scale(y_scale).orient("left"); | |
d3.select("svg") | |
.append("g") | |
.attr("class","y__axis") | |
.attr("transform","translate(60,0)") | |
.call(y_axis); | |
//add title | |
d3.select(".x__axis") | |
.append("text") | |
.text("age") | |
.attr("class","text") | |
.attr("x",150) | |
.attr("y",40); | |
d3.select(".y__axis") | |
.append("text") | |
.text("height") | |
.attr("class","text") | |
.attr("x",-20) | |
.attr("y",150) | |
.attr("transform","rotate(-90,-20,150)translate(-40,-20)"); | |
//add path | |
var line = d3.svg.line() | |
.x(function(d,i){return x_scale(i)}) | |
.y(function(d,i){return y_scale(d)}); | |
var path =d3.select("svg") | |
.append("path") | |
.data([data]) | |
.attr("d",line); | |
change(data,path,line); | |
} | |
function change(data,path,line){ | |
data.push(random()); | |
data.shift(); | |
path.transition() | |
.duration(750) | |
.attr("d",line) | |
.each("end",function(){change(data,path,line);}); | |
} | |
</script> | |
<style type="text/css"> | |
circle{ | |
stroke:black; | |
stroke-width:0.5px; | |
fill:blue; | |
opacity: 0.6; | |
} | |
.y__axis path{ | |
fill:none; | |
stroke:#00BFFF; | |
} | |
.x__axis path{ | |
fill:none; | |
stroke:#00BFFF; | |
} | |
.y__axis,.x__axis{ | |
font-family: sans-serif; | |
fill:#00BFFF; | |
stroke:none; | |
font-size: 13px; | |
} | |
.tick{ | |
fill:none; | |
stroke:#00BFFF; | |
} | |
svg{ | |
position: relative; | |
left: 100px; | |
} | |
.text{ | |
font-size: 20px; | |
font-weight: 700; | |
stroke:none; | |
fill:#0080FF; | |
} | |
path{ | |
stroke:blue; | |
fill:none; | |
} | |
</style> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
show(); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="http://d3js.org/d3.v2.js"></script> | |
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> | |
<script type="text/javascript"> | |
var random = d3.random.normal(0,0.3); | |
var data = d3.range(40).map(random); | |
function show(){ | |
d3.select("body") | |
.append("svg") | |
.attr("width",600) | |
.attr("height",300); | |
var x_scale = d3.scale.linear() | |
.range([60,580]) | |
.domain([-10,50]); | |
var y_scale = d3.scale.linear() | |
.range([280,20]) | |
.domain([-1,1]); | |
var x_axis=d3.svg.axis().scale(x_scale); | |
d3.select("svg") | |
.append("g") | |
.attr("class","x__axis") | |
.attr("transform","translate(0,280)") | |
.call(x_axis); | |
var y_axis=d3.svg.axis().scale(y_scale).orient("left"); | |
d3.select("svg") | |
.append("g") | |
.attr("class","y__axis") | |
.attr("transform","translate(55,0)") | |
.call(y_axis); | |
//add title | |
d3.select(".x__axis") | |
.append("text") | |
.text("age") | |
.attr("class","text") | |
.attr("x",150) | |
.attr("y",40); | |
d3.select(".y__axis") | |
.append("text") | |
.text("height") | |
.attr("class","text") | |
.attr("x",-20) | |
.attr("y",150) | |
.attr("transform","rotate(-90,-20,150)translate(-40,-20)"); | |
//add path | |
var line = d3.svg.line() | |
.x(function(d,i){return x_scale(i)}) | |
.y(function(d,i){return y_scale(d)}); | |
var path =d3.select("svg") | |
.append("path") | |
.data([data]) | |
.attr("d",line); | |
change(data,path,line,x_scale); | |
} | |
function change(data,path,line,x_scale){ | |
data.push(random()); | |
path.attr("d",line) | |
.transition() | |
.duration(250) | |
.ease("linear") | |
.each("end",function(){change(data,path,line,x_scale);}); | |
data.shift(); | |
} | |
</script> | |
<style type="text/css"> | |
circle{ | |
stroke:black; | |
stroke-width:0.5px; | |
fill:blue; | |
opacity: 0.6; | |
} | |
.y__axis path{ | |
fill:none; | |
stroke:#00BFFF; | |
} | |
.x__axis path{ | |
fill:none; | |
stroke:#00BFFF; | |
} | |
.y__axis,.x__axis{ | |
font-family: sans-serif; | |
fill:#00BFFF; | |
stroke:none; | |
font-size: 13px; | |
} | |
.tick{ | |
fill:none; | |
stroke:#00BFFF; | |
} | |
svg{ | |
position: relative; | |
left: 100px; | |
} | |
.text{ | |
font-size: 20px; | |
font-weight: 700; | |
stroke:none; | |
fill:#0080FF; | |
} | |
path{ | |
stroke:blue; | |
fill:none; | |
} | |
</style> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
show(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment