I'm trying to create a line graph using d3.js with this data structure:
var dataset1 = [ {"video_name": "Apples", "video_views": 100}, {"video_name": "Oranges", "video_views": 35}, {"video_name": "Grapes", "video_views": 20}, {"video_name": "Avocados", "video_views": 85}, {"video_name": "Tomatoes", "video_views": 60} ]
The index number of the object is the x-value and the "video_views" is the y-value.
The problem: It is appending the svg canvas, and the "g" element just fine, but the x and y values for each point in the graph are not being detected, so nothing is showing up.
// Scale values var Line_xScale = d3.scale.linear() .domain([0, 100]) .range([0, Line_Graph_Width]); var Line_yScale = d3.scale.linear() .domain([0, 100]) .range([0, Line_Graph_Height]); // This is where I suspect the problem is. // // SVG path equal to line var Path_Var = d3.svg.line() .x(function(d, i) { return i * 10; }) .y(function(d) { return Line_yScale(d.video_views); }); // Connect Element with Data group.selectAll('path') .data(dataset1) .enter() .append('path') .attr('d', Path_Var) .attr('fill', 'none') .attr('stroke', '#fff') .attr('stroke-width', 2);
Any help is appreciated. Thanks for reading.