[英]d3 scaling basic shapes
I'm trying to dynamically scale some shapes based on the data.我正在尝试根据数据动态缩放一些形状。 Here's what I have so far:
这是我到目前为止所拥有的:
svg.selectAll(".point")
.data(data)
.enter()
.append("path")
.attr("class", "point")
.attr("d", d3.svg.symbol().type("triangle-up"))
.attr("transform", function(d) { return "translate(" + x(d.x) + "," +
y(d.y) + ")"; });
Is there another attr that I can add?我可以添加另一个属性吗? I tried to use the following but not working:
我尝试使用以下但不起作用:
.attr("transform", "scale(xMap)");
xMap is a value in data scaled to a range. xMap 是缩放到某个范围的数据中的值。
You can do the translate
and the scale
in the same anonymous function.您可以在同一个匿名函数中进行
translate
和scale
。 Besides that, you have to concatenate the string with the number.除此之外,您必须将字符串与数字连接起来。 The way you're doing...
你这样做的方式...
"scale(xMap)"
... you're passing literally "xMap" to the scale()
. ...您将字面上的“xMap”传递给
scale()
。
Thus, it should be:因此,它应该是:
.attr("transform", function(d) {
return "translate(" + x(d.x) + "," + y(d.y) + ") scale(" + xMap + ")";
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.