I have this messy and ugly nested json parse calls(!!) which I am trying to simplify, I was hoping with d3.queue. The first json is used by function doFirstChart to do a chart after some basic typesetting. The function makes the chart and also returns some extra data which are used together with the second json file and another user-defined parameter by the function doSecondChart to do the next chart.
var c = 'someValue'
d3.json(countryJson, function (data) {
data.forEach(function (d) {
d.Country_Num = +d.Country_Num
d.y = +d.Y
d.x = +d.X
});
dataOut = doFirstChart(data);
d3.json(salesJson, function (salesData) {
salesData.forEach(function (d) {
d.Expt = +d.Expt
d.x = +d.x
d.y = +d.y
});
doSecondChart(dataOut, salesData, c)
console.log("Done!!")
});
});
It sounds like d3.queue is the appropriate tool for these situations, I have failed however to make it work even with a simplified example. For example (ignoring the exta parameter c) the following I was hoping to do trick but obviously I am not using it correctly.
d3.queue()
.defer(d3.json, 'path\to\country\data')
.await(doFirstChart)
.defer(d3.json, 'path\to\sales\data')
.await(doSecondChart)
I dont even get right the simplest of all:
d3.queue()
.defer(d3.json, 'path\to\country\data')
.await(doFirstChart)
How is this working please?
doFirstChart()function? Can you show the function declaration for it? (with it's declared parameters)d3.queueanymore, use Promises then