-
-
Save brjadams/5815277 to your computer and use it in GitHub Desktop.
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
createVisitsTimeSeries: function(container, visit_data){ | |
var margin = {top: 5, right: 5, bottom: 5, left: 5}, | |
width = $(container).width() - (margin.left - margin.right), | |
height = $(container).height() + 50; | |
var parseDate = d3.time.format("%Y-%m-%d").parse; | |
entries = d3.values(visit_data); | |
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 area = d3.svg.area() | |
.x(function(d) { return x(d.date); }) | |
.y0(height) | |
.y1(function(d) { return y(d.visits); }); | |
var svg = d3.select(container).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 + ")"); | |
console.log('visits', visit_data); | |
x.domain(d3.extent(entries, function(d) { | |
console.log('d', d); | |
return d.date; })); | |
y.domain([0, d3.max(entries, function(d) { return d.visits; })]); | |
svg.append("path") | |
.datum(entries) | |
.attr("class", "area") | |
.attr("d", area); | |
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"); | |
}, |
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
[ | |
{ | |
"date": "2013-06-01", | |
"visits": 5 | |
}, | |
{ | |
"date": "2013-06-02", | |
"visits": 10 | |
}, | |
{ | |
"date": "2013-06-03", | |
"visits": 12 | |
}, | |
{ | |
"date": "2013-06-04", | |
"visits": 8 | |
}, | |
{ | |
"date": "2013-06-05", | |
"visits": 3 | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
error is on d3 line 74.
Error: Problem parsing d="MNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,0LNaN,0LNaN,0LNaN,0LNaN,0Z"