How to get a path centroid d3
问题 I cant use the .centroid() method because its returns [NaN,Nan]. I dont know what is the right data format. var pathh = d3.geo.path(); d3.selectAll("path.line") .each(function (d, i) { var centroid = pathh.centroid(d); console.log('Centroid at: ', d,+ centroid[0] + ', ' + centroid[1]); }); My data format is: One object is one point(vertex) of the polygon 0: Object area_id: "IVP001" vertex_id: "37451" x: "100" y: "100" 1: Object area_id: "IVP001" vertex_id: "37452" x: "150" y: "120" 2: Object