var parseTime = d3.timeParse('%a %b %d %H:%M:%S +0000 %Y'); var formatTime = d3.timeFormat('%Y-%m-%d'); var parseFormattedTime = d3.timeParse('%Y-%m-%d'); var lineChart = function(data){ // set the dimensions and margins of the graph var margin = {top: 20, right: 20, bottom: 60, left: 50}, width = 500 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; // set the ranges var x = d3.scaleTime().range([0, width]); var y = d3.scaleLinear().range([height, 0]); //add a new svg to hold the chart 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 + ")"); // Scale the range of the data x.domain(d3.extent(data, function(d) { return parseTime(d.created_at); })); y.domain(d3.extent(data, function(d) { return +d.favorite_count; })); // Add the line path svg.selectAll("circle") .data(data) .enter().append('circle') .attr('cx', function(d) { return x(parseTime(d.created_at)); }) .attr('cy', function(d) { return y(+d.favorite_count); }) // Add the X Axis svg.append("g") .attr("transform", "translate(0," + height + ")") .call(d3.axisBottom(x)); // Add the Y Axis svg.append("g") .call(d3.axisLeft(y)); };