简体   繁体   English

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

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

I'm working with d3 version 5 to create a scatterplot. 我正在使用d3版本5创建散点图。

The following code works smoothly. 以下代码可以正常运行。

 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) + ")"; }) }); 

But when I use d inside any function, it breaks the display. 但是,当我在任何函数中使用d时,它将破坏显示。 Even if I use almost the simplest function possible. 即使我使用了几乎最简单的功能。

 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) + ")"; }) }); 

Actually, the error is not because of using d. 实际上,该错误不是由于使用d而引起的。 The issue is all about not closing the function properly. 问题全在于未正确关闭功能。 Make sure you are opening and closing curly braces properly. 确保正确打开和关闭大括号。 Please try this. 请尝试这个。

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