【问题标题】:D3 lines getting rendered as polygonsD3 线被渲染为多边形
【发布时间】:2012-11-23 01:35:16
【问题描述】:

我正在尝试使用 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));

【问题讨论】:

    标签: javascript d3.js data-visualization


    【解决方案1】:

    尝试在附加路径时显式设置fillstroke,即

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-12
      • 1970-01-01
      • 2012-02-05
      • 2011-08-16
      • 1970-01-01
      • 2021-07-22
      • 1970-01-01
      相关资源
      最近更新 更多