Using the lineChart.html from the NVD3 examples, I've replaced the code as follows:
//data = sinAndCos();
data = getDataIntensity();
function getDataIntensity() {
mySet = {};
mySet.values = [];
mySet.key = "Intensity";
mySet.color = "#ff7f0e";
mySet.strokeWidth = 4;
d3.csv('20170906perfmix.csv', function(dat) {
dat.forEach(function(d,i) {
mySet.values.push({x: i, y: +d.Intensity});
});
});
return [mySet];
}
I get the No Data Available message. I added a button to call chart.update() and then the data displays correctly. I understand this is probably due to the fact things are running asynchronously and the return of [mySet] occurs before all the data points are pushed onto the 'values' array.
How do I get this function to wait for all the data values to complete before returning?
Update: Now I'm confused about what is happening... if I console.log(mySet) prior to the return from getDataIntensity() it appears that all the values are there when using Chrome inspector. After calling chart.update() I do see that a member 'seriesIndex' has been set to 0 in the data object. Setting this value in mySet prior to the return has no effect. I get the No Data message on the first load in the browser.
Update2: fixed code by calling chart.update() within the callback
d3.csv('20170906perfmix.csv', function(dat) {
dat.forEach(function(d,i) {
mySet.values.push({x: i, y: +d.Intensity});
});
chart.update(); // fixes issue
});
return [mySet];