javascript - 在定义我的圆的坐标时添加到我当前的 attr cx 值
问题描述
下面给出的是我定义在图表上绘制点的位置的代码。问题是,我通过 xMap 获得的值有一点偏差,所以我想给它加 10 分。然而,这是不可能的,因为 xMap 不是一个简单的数值。
var dot = svg.selectAll("circle")
.data(data3)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 7)
.attr("cx", xMap)
.attr("cy", yMap)
.style("fill", "rgb(0,0,0)")
下面给出了到达 xMap 的代码:
var y = d3.scale.linear()
.domain([0, 100])
.range([height, 0]);
var xValue = function(d) {return d.Score;}
var xMap = function(d) { return x(xValue(d));}
理想情况下我只想说
.attr("cx", xMap + 5)
但这会导致错误“错误:属性cx:预期长度,”函数(d){重新......“......”
提前致谢!
解决方案
您可以使用以下解决方案来解决您的问题:
var dot = svg.selectAll("circle")
.data(data3)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 7)
.attr("cx", d => x(d.Score) + 5)
.attr("cy", d => y(d.value))
.style("fill", "black");
推荐阅读
- python - 如何不断地添加到一个字符串?
- r - 如何删除R中同一列中匹配的部分字符串?
- java - EJB3 MessageDrivenBean 抛出异常 当使用外部 ActiveMQ 队列时,此类不被信任序列化为 ObjectMessage 有效负载
- linux - 使用 tee 将输入管道输入到两个进程替换
- firefox - xfce4-terminal 打开新选项卡而不是新实例
- java - 如何使用 fastxml.jackson 验证 scala 中的嵌套案例类
- matlab - ode45 收敛到正确的曲线形状,但有错误的解决方案
- python - 在python中求解方程组
- performance - 用于更改硬件的 CUDA 块大小和网格大小
- python - 在 tweepy 上使用用户对象时出现属性错误