javascript - Uncaught TypeError: Cannot read property 'position' of undefined (D3.JS) -


this error popped when tried retrieve json data , make line graph.

uncaught typeerror: cannot read property 'position' of undefined

here's js :

d3.json("../js/sample2.json", function(data) {     var canvas = d3.select("body").append("svg")             .attr("width", 500)             .attr("height", 500);      var = 0;     var group = canvas.append("g")             .attr("transform", "translate(100,100");       var line = d3.svg.line()             .x(function(d, i) {                 console.log("x" + d[0].position[i]);                 return d[0].position[i];             })             .y(function(d, i) {                 console.log("y" + d[1].position[i]);                 return d[1].position[i];             });      group.selectall("path")             .data([data]).enter()             .append("path")             .attr("d", line)             .attr("fill", "none")             .attr("stroke", "red")             .attr("stroke-width", 5); }); 

here's json :

[{"name": "x", "position":[40,60,80,100] },  {"name": "y", "position":[70,190,220,160]} ] 

my fiddle

can me out this?

i want line displayed data retrieved json file.

found solution:

d3.json("../js/sample2.json", function(data) {      var canvas = d3.select("body").append("svg")             .attr("width", 500)             .attr("height", 500);     console.log(data);      var group = canvas.append("g")             .attr("transform", "translate(100,100");       var line = d3.svg.line()             .x(function(d, i) { //                console.log(data[0].position[i]);                 return data[0].position[i];             })             .y(function(d, i) { //                console.log(data[1].position[i]);                 return data[1].position[i];             });       group.selectall("path")             .data([data]).enter()             .append("path")             .attr("d", line(data[0].position))             .attr("fill", "none")             .attr("stroke", "red")             .attr("stroke-width", 5); }); 
had provide .attr("d", line(data[0].position)) 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -