为什么我的坐标只在我的圆定义中未定义

Why are my coordinates undefined only inside my circle definition?

本文关键字:我的 定义 未定义 坐标 为什么      更新时间:2023-09-26

我有一组圆圈定义为

 nodes = [{
        x: xRange(xvalue),
        y: yRange(getY(xvalue)),
        ... 
}]
vis.selectAll(".nodes")
    .data(nodes)
    .enter().append("circle")
    .attr("class", "nodes")
    .attr("cx", function (d) {
        return d.x;
        (coordinate display)
    })
    .attr("cy", function (d) {
        return d.y;
    })
    .attr("r", "7px")
    .attr("fill", "black")
    .attr("transform", function (p) {
        return "translate(" + p.x + "," + p.y + ")";
    })
我对这些圆圈

遇到的问题是,尽管在其他任何地方都定义了圆圈,但从nodes中获取的坐标是未定义的。这是一个表示此问题的测试用例,其中应该显示其中一个点的坐标,但不是,因为它似乎未定义。为了证明轴有效,我在图形的第一象限放置了一个点。有什么理由可以解释为什么会发生这种情况吗?

在运行逻辑之前返回:

.attr("cx", function (d) {
        return d.x;
        (coordinate display)
    })

更改为 :

.attr("cx", function (d) {
           (coordinate display)
           return d.x;
        })