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.
Asked
Active
Viewed 1,028 times
-1
-
This is covered in [this tutorial](http://bost.ocks.org/mike/bar/). – Lars Kotthoff Nov 12 '15 at 16:13
-
this is again static data, I am pasting my code here so that you have better understanding of what I actually want. – Anbreen Awan Nov 12 '15 at 16:59
-
svg.selectAll(".bartext") .data(data) .enter() .append("text") .transition() .delay(290000) .duration(300000) .attr("class", "bartext") .attr("text-anchor", "middle") .attr("fill", "black") .style("font-weight","bold") .attr("x",function (d, i) { return convert.x(d.alarm)+30; }) .attr("y", function(d,i) { return convert.y(d.value); }) .text(function(d){ return d.value;//// here I want to add counter here, from 0 to d.value, }); – Anbreen Awan Nov 12 '15 at 17:03
-
Sorry, don't understand what you're looking for. – Lars Kotthoff Nov 12 '15 at 18:04
-
http://javascript.tutorialhorizon.com/2015/02/07/using-d3-to-draw-a-bar-chart-with-an-axis-and-some-basic-transitions/ this is what, I have done already, but now I am trying to add the value/count[exact status/height of a bar] as bar grows up starting from o to max size of each bar. just like a counter in c++. hope some one understand and answer my question. – Anbreen Awan Nov 12 '15 at 18:14
-
See https://stackoverflow.com/questions/13454993/changing-number-displayed-as-svg-text-gradually-with-d3-transition – Lars Kotthoff Nov 12 '15 at 18:26
1 Answers
0
Thanks Lars Kotthoff it was very helpful. I am pasting my code here hope it would be helpful for others. `
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)})
};
});
`

Anbreen Awan
- 29
- 6