【问题标题】:Why is circle getting appended outside the body? D3.js为什么圆圈会附加在体外? D3.js
【发布时间】:2020-10-31 06:34:55
【问题描述】:

试图制作散点图,但圆圈被附加到 SVG 之外。

var line_fatality = svg
    .append('g')
    .classed('fatality',true)
    .data(check[0].values)
    .enter()
    .append("circle")
    .attr('cx', (function (d, i) {
        return x(d.date)
    }))
    .attr('cy', (function (d, i) { return y(d.fatality) }))
    .attr("r", 1.5)
    .style("fill", "#69b3a2")

Circle SVG

【问题讨论】:

    标签: javascript d3.js data-visualization


    【解决方案1】:

    修复它。对于任何想知道为什么它不起作用的人,请尝试在您的代码中添加 selectAll。

    var line_fatality = svg
            .selectAll("dot")
            .append('g')
            .classed('fatality',true)
            .data(check[0].values)
            .enter()
            .append("circle")
            .attr('cx', (function (d, i) {
                return x(d.date)
            }))
            .attr('cy', (function (d, i) { return y(d.fatality) }))
            .attr("r", 1.5)
            .style("fill", "#69b3a2")
    

    Updated SVG

    【讨论】:

      猜你喜欢
      • 2014-05-26
      • 2016-09-06
      • 2017-10-15
      • 2012-07-05
      • 1970-01-01
      • 2013-11-24
      • 2019-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多