简体   繁体   English

D3转换价值

[英]D3 Translate Value

I'm working on a D3 project right now, and the following code WORKS but I don't understand why. 我现在正在D3项目上,下面的代码可以工作,但我不明白为什么。

When translating (moving) the position of a Y-Scale of an area chart (in this example it is the yAxis variable that I call in the last line of code) I should enter in the value of the transform attribute surrounded by two "+" icons. 在平移(移动)面积图的Y比例尺的位置时(在此示例中,这是我在代码的最后一行中调用的yAxis变量),我应该输入由两个“ +”括起来的transform属性的值”图标。 Why is this value broken up with quotation marks and what is the purpose of the + icons? 为什么此值用引号引起来,+图标的作用是什么? If someone could break down the last line of code that would be very helpful. 如果有人可以破坏代码的最后一行,那将非常有帮助。

var margin = {left: 50, right: 50, top: 40, bottom: 0};

var yScale = d3.scaleLinear()
.domain([0, 229])
.range([height, 0]);

var yAxis = d3.axisLeft(yScale);

svg.append("g").attr("class", "axis y").call(yAxis)
.attr("transform","translate("+margin.left+",200)").call(yAxis);

The + is string concatenation*. +是字符串连接*。 In your case, "translate("+margin.left+",200)" is changed to "translate(50,200)" because margin.left === 50. 在您的情况下,因为margin.left === 50, "translate("+margin.left+",200)"更改为"translate(50,200)"

*or, more appropriately the add function for strings. *,或者更合适的是字符串的add函数。

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

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