Example using spin.js during load of JSON data for a D3 chart
Showing the spinner/loader being triggered before the JSON callback, and stopped within the JSON callback (hence after the JSON data has been loaded):
// loader settings
var target = document.getElementById('#chart-id');
function init() {
// trigger loader
var spinner = new Spinner(opts).spin(target);
// load json data
data.loadJson(chartConfig.data_url, function(data) {
// stop the loader
spinner.stop();
// code to execute within callback
});
}
init();
Modified http://d3js.org/d3.v3.min.js to a secure url
https://d3js.org/d3.v3.min.js
https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.0.1/spin.min.js