Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


D3js Animated Counter

16 Dec 2021 »

https://codepen.io/tiffk935/pen/zYxPpyB

const start = 0;
const end = 9999;

d3.select('#counter').transition()
  .tween("text", () => {
    const interpolator = d3.interpolateNumber(0, end);
    return function(t) {
      d3.select(this).text(Math.round(interpolator(t))) 
    }
  })
  .duration(1000);