Javascript d3工具提示根据正值和负值不同的文本
我想知道为什么不可能做到以下几点:Javascript d3工具提示根据正值和负值不同的文本,javascript,d3.js,Javascript,D3.js,我想知道为什么不可能做到以下几点: div.text(function(d) {return " bought " + d.USD;}) 它适用于代码前面的红色或绿色圆圈: .style("fill", function(d) {if (d.USD <= 0) {return "green"} else { return "red" };}) 以下是我负责绘制圆圈和添加工具提示的代码摘录: // Draw circle aro
div.text(function(d) {return " bought " + d.USD;})
它适用于代码前面的红色或绿色圆圈:
.style("fill", function(d) {if (d.USD <= 0) {return "green"}
else { return "red" };})
以下是我负责绘制圆圈和添加工具提示的代码摘录:
// Draw circle around values
svg.selectAll("dot")
.data(bitstamp_data)
.enter().append("circle")
.attr("r", function(d) { return Math.sqrt(Math.abs(d.USD)) - 5; })
.attr("cx", function(d) { return x(d.date); })
.attr("cy", function(d) { return y(d.Price); })
.style("fill-opacity", 0.7)
.attr("stroke", "black")
// Show different colour depending on buying or selling USD based on positive or negative d.USD
.style("fill", function(d) {
if (d.USD <= 0) {return "green"}
else { return "red" }
;})
// Tooltip section
.on("mouseover", function(d) {
div.transition()
.duration(400)
.style("opacity", .9);
div.text(function(d) {return " bought " + d.USD
;})
.style("left", (d3.event.pageX + 15) + "px")
.attr("stroke", "black")
.style("top", (d3.event.pageY - 28) + "px");
})
你应该可以写:div.text bunded+d.USD当你说这是不可能的时候,你的意思是什么?最终,我想对div.text做同样的if条件,取决于值是正值还是负值。它使用nemesv解决方案工作,但我不能以这种方式实现条件。我所说的不可能的意思是,当我写div.textfunctiond等时,工具提示不再出现。。。。