[英]d3 js - trouble updating text elements in multiple line chart
UPDATE: 更新:
Got a working jsFiddle here: 在这里有一个工作的jsFiddle:
I have gotten it to work after this, by moving this snippet last but I have a hard time understanding why - and I suspect this isn't a good way to do transitions and update. 在此之后,我已经通过最后移动此代码段来使其工作,但是我很难理解为什么-我怀疑这不是进行过渡和更新的好方法。 Any help is much appreciated.
任何帮助深表感谢。
text.datum(function(d) {return { name: d.name, value: d.values[d.values.length - 1]}; })
.transition()
.duration(750)
.attr("transform", function(d) {return "translate(" + x(d.value.Datum) + "," + y(d.value.Antal) + ")";});
Had another question that didn't deal with the text part of the chart but rather the lines, answered here: Question 还有另一个问题不涉及图表的文本部分,而是折线,请在此处回答: 问题
At the same time I solved the lines I also solved how to change the text. 同时我解决了各行,也解决了如何更改文本。 Like in the above question.
就像上面的问题一样。
var t01 = svg.selectAll(".city")
.data(dsMainArr,function key(d) {return d.name;});
var t01Enter = t01.enter().append("g")
.attr("class", "city");
t01Enter.append("text")
.attr("class", "textEnd")
.datum(function(d) {return {name: d.name, value: d.values[d.values.length - 1]}; })
.attr("transform", function(d) { return "translate(" + x(d.value.Datum) + "," + y(d.value.Antal) + ")"; })
.attr("x", 3)
.attr("dy", ".35em")
.text(function(d) { return d.name; })
.transition().duration(750);
t01.exit().transition().duration(750).remove();
var t1 = t01.transition();
t1.select("text").attr("transform",
function(d) { var len = d.values.length;
return "translate(" + x(d.values[len-1].Datum)
+ ","
+ y(d.values[len-1].Antal) + ")";
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.