score:53
Accepted answer
It seems d3JS already provides a suitable function called "tween"
Here is the important part of the code example.
.tween("text", function(d) {
var i = d3.interpolate(this.textContent, d),
prec = (d + "").split("."),
round = (prec.length > 1) ? Math.pow(10, prec[1].length) : 1;
return function(t) {
this.textContent = Math.round(i(t) * round) / round;
};
});
http://jsfiddle.net/c5YVX/280/
You can increment them over a given time interval from any start to any end value regardless their number precision.
Its implemented for SVG text but of course works the same for standard html text.
If you only need the plain tween function for rounded numbers, it gets a bit more leightweight.
.tween("text", function(d) {
var i = d3.interpolate(this.textContent, d),
return function(t) {
this.textContent = Math.round(i(t));
};
});
Source: stackoverflow.com
Related Query
- Changing number displayed as svg text gradually, with D3 transition
- Appending multiple svg text with d3
- D3.js how to transition in opposite direction with basic SVG elements
- How to transform (rotate) svg text element without changing coordinates?
- Hide and show svg element with transition
- SVG text alignment issues with a curved textpath
- transition a circle into a line by unrolling it with SVG and d3
- SVG text color with correspond to background
- Avoid jumping of an SVG Text with text-anchor while dragging
- Match SVG text element id with data id using D3
- Giving SVG text a background with rect
- Changing number values for text on Y Axis label for dc.js ScatterPlot
- Transition between paths with different number of data points
- How to apply text transition to number in d3
- How do I append the text tag to just one svg e.g. svg tag with "id=50"?
- Reliable way to determine the width of svg text styled with @font-face
- How to make an svg text with d3.js that flashes from black to white an back continuously?
- Adding tooltip to SVG elements with text from an array
- Align svg text inline with d3.js legend
- How do I do a line break with SVG text element ?
- Select content of text element with tspan specifier in SVG with D3js
- Automatically place text from two data variables into an svg with d3
- Transition between a circle and a line with svg and d3
- Multiple force-directed graphs in 1 svg (problems with text display)
- SVG styling of text with NVD3 library
- Changing transform values in SVG with D3.js
- How to draw non-scalable text in SVG with Javascript?
- d3: replace a number value with text on x axis
- How do I align svg foreignObject with a text element?
- d3js Text Transition I example with v3 library
More Query from same tag
- Data loading issue in Table using D3 version 4
- Grouped line chart, how to draw lines in a repeating pattern
- D3 y-axis percent display
- .append() to different selection depending on condition?
- C3.js bubble chart selection
- D3js append different ellements into SVG in d3.hierarchy by type of JSON element
- d3 enter().append() not appending all elements of my array
- d3js multi series line chart, appending circles
- dc.js - dynamically change valueAccessor of a stacked layer in a lineChart and redraw it
- Find in which polygon a GeoJSON point lies in, in NodeJS
- D3 force directed graph nodes with nested circles
- d3 - drag node groups in radial tree layout without jumping to new position on click
- D3 Multiline Chart with transition
- Binding an event during an update() transition
- No update of x axis
- Projection in D3 v5 not working with coordinates data
- Cubism callback array seemingly replaced
- How can I enable and disable mouseover events?
- How to change labels on the control button in NVD3?
- How to load a .csv file into crossfilter with d3?
- display rectangles based on values
- D3 2 dimensional brush not slideable
- Creating unique scales for parallel coordinates using d3 (multivariate)
- Start with closed nodes in indented tree
- d3 zoom - how to set initial transform
- How to add an arrow links in D3.js?
- Export d3 word cloud as png with button
- How to center a text on a svg image using d3.js?
- How to make a color gradient bar using d3js
- Referencing different sets of elements using d3 js