5
<script type="text/javascript" src="../../d3.v2.js"></script>
6
<style type="text/css">
22
shape-rendering: crispEdges;
41
.grid path, .axis path {
48
<script type="text/javascript">
50
var m = [10, 50, 20, 10],
51
w = 960 - m[1] - m[3],
52
h = 500 - m[0] - m[2],
53
parse = d3.time.format("%Y-%m-%d").parse;
55
// Scales. Note the inverted domain for the y-scale: bigger is up!
56
var x = d3.time.scale().range([20, w - 20]),
57
y = d3.scale.linear().range([h - 20, 20]);
60
var xAxis = d3.svg.axis().scale(x).orient("bottom"),
61
yAxis = d3.svg.axis().scale(y).orient("right");
64
var area = d3.svg.area()
65
.x(function(d) { return x(d.Date); })
67
.y1(function(d) { return y(d.Close); });
69
var svg = d3.select("body").append("svg")
70
.attr("width", w + m[1] + m[3])
71
.attr("height", h + m[0] + m[2])
73
.attr("transform", "translate(" + m[3] + "," + m[0] + ")");
79
d3.csv("dji.csv", function(data) {
81
// Parse dates and numbers.
82
data.reverse().forEach(function(d) {
83
d.Date = parse(d.Date);
87
// Compute the minimum and maximum date, and the maximum price.
88
x.domain([data[0].Date, data[data.length - 1].Date]);
89
y.domain([0, d3.max(data, function(d) { return d.Close; })]);
92
.attr("class", "x grid")
93
.attr("transform", "translate(0," + h + ")")
94
.call(xAxis.tickSubdivide(1).tickSize(-h));
97
.attr("class", "y grid")
98
.attr("transform", "translate(" + w + ",0)")
99
.call(yAxis.tickSubdivide(1).tickSize(-w));
102
.attr("class", "x axis")
103
.attr("transform", "translate(0," + h + ")")
104
.call(xAxis.tickSubdivide(0).tickSize(6));
107
.attr("class", "y axis")
108
.attr("transform", "translate(" + w + ",0)")
109
.call(yAxis.tickSubdivide(0).tickSize(6));
112
.attr("class", "area")
113
.attr("d", area(data));