Skip to content

Commit

Permalink
Adds sample line chart.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreLouisCaron committed Feb 20, 2016
1 parent 183d669 commit bffb56a
Show file tree
Hide file tree
Showing 4 changed files with 1,384 additions and 4 deletions.
16 changes: 16 additions & 0 deletions c4cast/assets/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.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;
}
52 changes: 52 additions & 0 deletions c4cast/assets/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function line_chart(svg, width, height, data)
{
var margin = {top: 20, right: 20, bottom: 30, left: 50};
width = width - margin.left - margin.right,
height = height - margin.top - margin.bottom;

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()
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.close); });
x.domain(d3.extent(data, function(d) { return d.date; }));
y.domain(d3.extent(data, function(d) { return d.close; }));

svg = svg
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr(
"transform", "translate(" + margin.left + "," + margin.top + ")"
);

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);

}
Loading

0 comments on commit bffb56a

Please sign in to comment.