score:1

Accepted answer

There is nothing different (as a function I mean) in d3.json() or the other D3 fetch functions. You can put it inside a setInterval or, since this is a D3 code, inside a d3.interval.

Here is a simple demo, instead of your API I'm using an API that generates random values, so you can see that it works:

getData();
d3.interval(getData, 5000);

function getData() {
  d3.json("https://randomuser.me/api/").then(function(data) {
    console.log(JSON.stringify(data.results[0].name));
  })
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>

I'm calling the function the regular way the first time, otherwise it would be called only after 5 seconds. Regarding the delay, if it's called just once, you can use setTimeout (or d3.timeout).


Related Query

More Query from same tag