Skip to content

Instantly share code, notes, and snippets.

@CamonZ
Forked from mbostock/.block
Last active August 29, 2015 14:11
Show Gist options
  • Save CamonZ/27edf10c0feca5f476ac to your computer and use it in GitHub Desktop.
Save CamonZ/27edf10c0feca5f476ac to your computer and use it in GitHub Desktop.
date close
1-May-12 582.13
30-Apr-12 583.98
27-Apr-12 603.00
26-Apr-12 607.70
25-Apr-12 610.00
24-Apr-12 560.28
23-Apr-12 571.70
20-Apr-12 572.98
19-Apr-12 587.44
18-Apr-12 608.34
17-Apr-12 609.70
16-Apr-12 580.13
13-Apr-12 605.23
12-Apr-12 622.77
11-Apr-12 626.20
10-Apr-12 628.44
9-Apr-12 636.23
5-Apr-12 633.68
4-Apr-12 624.31
3-Apr-12 629.32
2-Apr-12 618.63
30-Mar-12 599.55
29-Mar-12 609.86
28-Mar-12 617.62
27-Mar-12 614.48
26-Mar-12 606.98
23-Mar-12 596.05
22-Mar-12 599.34
21-Mar-12 602.50
20-Mar-12 605.96
19-Mar-12 601.10
16-Mar-12 585.57
15-Mar-12 585.56
14-Mar-12 589.58
13-Mar-12 568.10
12-Mar-12 552.00
9-Mar-12 545.17
8-Mar-12 541.99
7-Mar-12 530.69
6-Mar-12 530.26
5-Mar-12 533.16
2-Mar-12 545.18
1-Mar-12 544.47
29-Feb-12 542.44
28-Feb-12 535.41
27-Feb-12 525.76
24-Feb-12 522.41
23-Feb-12 516.39
22-Feb-12 513.04
21-Feb-12 514.85
17-Feb-12 502.12
16-Feb-12 502.21
15-Feb-12 497.67
14-Feb-12 509.46
13-Feb-12 502.60
10-Feb-12 533.42
9-Feb-12 523.17
8-Feb-12 556.68
7-Feb-12 568.83
6-Feb-12 563.97
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.x.axis path {
display: none;
}
.line {
fill: none;
stroke: steelblue;
stroke-width: 1.5px;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.js"></script>
<script>
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var parseDate = d3.time.format("%d-%b-%y").parse;
var x = d3.time.scale()
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var line = d3.svg.line()
.interpolate("monotone")
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.close); });
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.tsv("data.tsv", function(error, data) {
data.forEach(function(d) {
d.date = parseDate(d.date);
d.close = +d.close;
});
x.domain(d3.extent(data, function(d) { return d.date; }));
y.domain(d3.extent(data, function(d) { return d.close; }));
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Price ($)");
svg.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment