Created
August 16, 2013 23:19
-
-
Save jugglinmike/6254347 to your computer and use it in GitHub Desktop.
Experimenting with d3.svg.line support in d3.chart
This file contains 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
var LineChart = d3.chart("Line", { | |
initialize: function() { | |
var path = this.base.append("path") | |
.classed("line", true); | |
var x = this.x = d3.time.scale() | |
.range([0, width]); | |
var y = this.y = d3.scale.linear() | |
.range([height, 0]); | |
var line = d3.svg.line() | |
.x(function(d) { return x(d.date); }) | |
.y(function(d) { return y(d.close); }); | |
this.layer("line", path, { | |
dataBind: function(data) { | |
this.datum(data) | |
.attr("d", line); | |
} | |
}); | |
}, | |
transform: function(data) { | |
this.x.domain(d3.extent(data, function(d) { return d.date; })); | |
this.y.domain(d3.extent(data, function(d) { return d.close; })); | |
return data; | |
} | |
}); | |
var myLine = d3.select("body").append("svg").chart("Line"); | |
myLine.draw(data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment