Is there any function in d3 for counter?

时间:2015-11-12 10:38:50

标签: d3.js

enter image description herethis is my visualization it displays count values for each bar after transition of 5 min when all bars properly grow in length. I want to show count values starting from 0 to height of bar. is this possible? if yes kindly help me out.

1 个答案:

答案 0 :(得分:0)

感谢Lars Kotthoff,这非常有帮助。我在这里粘贴我的代码希望它对其他人有用。 `

svg.selectAll(".bartext")
.data(data)
.enter()
.append("text")
.attr("class", "bartext")
.attr("text-anchor", "middle")
.attr("fill", "black")
.style("font-weight","bold")
.attr("x",function (d, i) {
        return  convert.x(d.alarm);
      })
.attr("y", maxHeight)
 .transition()
    .duration(180000)
        .tween("text", function(d) {
            var i = d3.interpolate(this.textContent, d.value),
                prec = (d + "").split("."),
                round = (prec.length > 1) ? Math.pow(10, prec[1].length) : 1;
            return function(t) {
              var j=maxHeight;
                this.textContent = Math.round(i(t) * round) / round;
                svg.selectAll(".bartext")
                .attr("y",function(d){return convert.y(this.textContent)})
              };
        });

`

相关问题