Mike
Your asynchronous callbacks can be invoked in arbitrary order. So,
even if your code looks like this:
d3.csv("data/data_file1.csv", function(csv) {
console.log("data_file1 loaded");
});
d3.csv("data/data_file2.csv", function(csv) {
console_log("data_file2 loaded");
});
You might see the following on the console:
data_file2 loaded
data_file1 loaded
This is particularly true if data_file1 is larger than data_file2;
they are typically loaded in parallel by your browser, so the larger
one will take longer to load.
Another issue is that console.log lazily displays nested objects and
arrays. If the contents of your array (`csv`) are later changed by
your code, an earlier console.log might display the value of the data
later, rather than at the time you logged in. One way to force
console.log to display the current value of an object is to convert it
to JSON:
console.log("data_file2", JSON.stringify(csv));
Another likely cause is that one of your two files (data_file1.csv) is
invalid CSV. One helpful way is to debug via the developer console.
Try typing this in and seeing what happens:
d3.csv("data_file1.csv", function(csv) { console.log(csv); });
Then run it again (after waiting for the file to load, of course!).
Then point it at your other file and see if it works.
Mike
test [{"country":"sweden","year":"1950","ind1":"50"},{"country":"norway","year":"1950","ind1":"60"}]
test2 [{"country":"sweden","year":"1950","ind2":"50"},{"country":"norway","year":"1950","ind2":"60"},{"country":"denmark","year":"1960","ind2":"70"}]
I added "test" and "test2" to the front so I could see which file it
was printing. I'm running Chrome 11.0.696.57 beta on Mac OS X, with
python -m SimpleHTTPServer to serve files on my local machine. I also
tried this on Safari 5.0.5 and Firefox 4 and saw identical results.
Are you using a local server? If you run the example out of file:
you'll get security errors.
Mike
Ah, yes. That's a big with regular expression literals in FF 3.6; it's
not creating a new RegExp object each time parseRows runs, so
`lastIndex` isn't being reset to zero. I'll commit a work-around in
1.14.1.
Mike