繁体   English   中英

属性函数(.attr(“ d”,…语句)中的d3函数中断代码(D3版本5-Scatterplot)

[英]d3 function inside my attribute function (.attr(“d”, … statement) breaks code (D3 Version 5 - Scatterplot )

我正在使用d3版本5创建散点图。

以下代码可以正常运行。

 svg.selectAll(".point") .data(data) .enter().append("path") .attr("class", "point") .attr("d", d3.symbol().type(d3.symbolCross)) .attr("Fill",'steelblue') .attr("transform", function(d) {return "translate("+ x(dx) + "," + y(dy) + ")"; }) }); 

但是,当我在任何函数中使用d时,它将破坏显示。 即使我使用了几乎最简单的功能。

 svg.selectAll(".point") .data(data) .enter().append("path") .attr("class", "point") .attr("d", function(d) { return "d3.symbol().type(d3.symbolCross)";} .attr("Fill",'steelblue') .attr("transform", function(d) { return "translate(" + x(dx) + "," + y(dy) + ")"; }) }); 

实际上,该错误不是由于使用d而引起的。 问题全在于未正确关闭功能。 确保正确打开和关闭大括号。 请尝试这个。

svg.selectAll(".point")
            .data(data)
            .enter().append("path")
            .attr("class", "point")
            .attr("d", d3.symbol().type(d3.symbolCross))       
            .attr("Fill",'steelblue')
            .attr("transform", (d) => "translate(" + d.x + "," + d.y + ")");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM