score:1
Accepted answer
Your question (I mean, the desired outcome) is not exactly clear, but I guess that you can get what you want using a transition with delay, instead of each
:
function colorChange() {
var color = d3.select("circle").style("fill");
if (color == "rgb(0, 0, 255)") {
d3.selectAll("circle")
.transition()
.delay((d, i) => i * 50)
.duration(100)
.style("fill", "red");
} else {
d3.selectAll("circle")
.transition()
.delay((d, i) => i * 50)
.duration(100)
.style("fill", "blue");
}
}
Here is the updated code (I changed the interval to 5 secs, just to give time to paint all the circles, so please wait a little bit for the first call): https://bl.ocks.org/anonymous/raw/bf1921449e33d89ba6259167231f5b32/
score:0
This might do what you are trying to achieve:
d3.interval(colorChange, 2000);
function colorChange(){
var color = d3.select("circle").style("fill");
if (color == "rgb(0, 0, 255)")
d3.selectAll("circle").each(function(){
d3.select(this).style("fill","red");
// How long to wait in ms
sleep(100);
});
else
d3.selectAll("circle").style("fill","blue");
}
function sleep(ms) {
var now = new Date().getTime();
while(new Date().getTime() < now + ms){ /* do nothing */ }
}
Source: stackoverflow.com
Related Query
- In D3js how can I give delay for updating each node
- How can I connect two parent node into one child node and how to make a tooltip for each node in the tree pragmatically? in D3 js (SVG)
- How can I get "call" to execute for each data element in D3?
- In D3, how can I create multiple elements for each data element based on value in data?
- d3js force layout dynamically adding image or circle for each node
- How to give a class for all descendants of a tree node
- How can D3js pack layout use data join by key for updates?
- How change position node for level in d3JS
- how can i group JSON data and generate a graph of each group in D3js
- how do I set up a grouping query on the server side. I want set up the query so I can use it for a pie chart in front end, using d3js
- d3js - How to plot a multi line chart chart for multiple groups of items that can be updated?
- How can I make double click event on node in d3.js?
- MultiBar chart with nvd3 / d3 only shows labels for every other tick on the x-axis. How can I get them all to show up?
- How can I implement an invert function for a point scale?
- How can I set the each line color or width in SVG path
- Where can I get the .geojson file for India and not separate files for each state/territory or any other distinction?
- How can I plot positive and negative values for both axes in a scatter plot with d3?
- How can i get the startAngle and endAngle of each arc in the sunburst example using d3.js?
- For some reason, my D3 Map is displaying upside down - how can I flip it?
- how to give href to d3js text element
- How can I style a tooltip for an NVD3 Chart?
- How can I color ocean with topojson in d3 when I have coordinate info for land?
- How can I set an initial .focus() on a node in a d3.js sunburst chart?
- in d3.geo MultiPoint how can I provide different shapes for different poins?
- How can we create an onclick event for a d3 data map?
- How to bind an angularjs directive to a d3js node defined in a link function
- How can I create a doughnut chart with rounded edges only on one end of each segment?
- How can I choose a legible color to draw text on a bar in a d3js chart?
- How do you specify node colors for the d3 radial tree?
- Specifying nodeSize for each node individually in D3.js tree layout
More Query from same tag
- What is the difference between D3 and jQuery?
- D3 - change formatting if a column in the data exists
- Using Bootstrap Tooltip with SVG Object - Not Displaying Despite specifying Container
- How to make two sets of axis labels in grouped line graph in dimple.js?
- d3 concise axis update method
- Optimize javascript loop on CSV data
- Why are events from d3 in firefox not handled
- Why is d3 ignoring my color array?
- D3.js animating update
- d3.js path doesn't respect domain and range
- Recovering x-axis value on click - NVD3 LineChart
- d3 sorting of an array of objects
- Replace old content d3
- D3.js Adding links between elements in a radial tree (Hierarchical edge bundling elements)
- NVD3 - configuring ticks on axis
- Reading text file with special characters using d3.request
- d3js maximum and minimum on x scale.
- Error when generating line Chart, Uncaught TypeError: Cannot read property 'each' of undefined
- C3JS - Cannot read property 'category10' of undefined
- Multiple select in c3.js
- Google Chart Issue - Only the Wireframe is Visible
- How to save automatically a HTML SVG element generated dynamically
- How to size the chart to always fill the space
- Using JSON data in D3 Javascript visualisation
- failed to use d3 to update legend data, entering is empty for changed data
- Representing the most recently clicked D3 node in a text field
- How to get data labels to show in D3 stacked bar chart?
- Map tooltips in the wrong location
- d3.js not updating graph with new data
- Confusion about d3.interpolateObject