2012-12-05 81 views
2

我想用D3渲染线,但是当我尝试这样做时,线渲染为多边形。我不知道为什么。我收录了一张截图,向你展示它的样子。 下面是代码:D3线渲染为多边形

// Creates a time scale using the x_extent 
    // defined above 
    var x_scale = d3.time.scale() 
    .range([margin, width - margin]) 
    .domain(x_extent); 

    // Creates a similarity scale using the y_extent. 
    // defined above. 
    var y_scale = d3.scale.linear() 
    .range([height - margin, margin]) 
    .domain(y_extent); 

    // Construct a line. 
    var line = d3.svg.line() 
    .x(function(d) { 
     return x_scale(d.date); 
    }) 
    .y(function(d) { 
     return y_scale(d.similarity); 
    }); 

    // Render a line. 
    d3.select("svg") 
    .append("path") 
    .attr("d", line(data)); 

enter image description here

回答

4

尝试设置fillstroke明确追加路径时,即

d3.select("svg") 
    .append("path") 
    .attr("fill", "none") 
    .attr("stroke", "black") 
    .attr("d", line(data)); 
+0

谢谢你这么多拉尔斯! – egidra