D3: Difference between revisions
From charlesreid1
(Created page with "=Loading Data= To load multiple (arbitrary number) CSV files: <source lang="javascript"> var filesArray = ["myrandedata.csv","myrandndata.csv","myrandudata.csv"]; ...") |
No edit summary |
||
| Line 22: | Line 22: | ||
} | } | ||
</source> | </source> | ||
=Things I learned about D3 while modifying Parallel example= | |||
* Role of maps | |||
* Nesting functions | |||
* Scope of Javascript | |||
* The whole function notation | |||
* Loading multiple files | |||
* Loading data as CSV (associated array) or as text (plain multidimensional array) | |||
* Console | |||
* Accessing arrays using notation <nowiki>data[0]</nowiki> versus <nowiki>data['x1']</nowiki> versus <nowiki>data.x1</nowiki> | |||
Revision as of 06:11, 7 August 2012
Loading Data
To load multiple (arbitrary number) CSV files:
var filesArray = ["myrandedata.csv","myrandndata.csv","myrandudata.csv"];
var remaining = filesArray.length;
// from https://groups.google.com/forum/#!msg/d3-js/3Y9VHkOOdCM/YnmOPopWUxQJ
filesArray.forEach( function(f) {
d3.csv(f, function(data) {
mydata[f] = data;
if (!--remaining) doSomething();
});
});
function doSomething() {
filesArray.forEach( function(f) {
console.log( mydata[f] );
});
}
Things I learned about D3 while modifying Parallel example
- Role of maps
- Nesting functions
- Scope of Javascript
- The whole function notation
- Loading multiple files
- Loading data as CSV (associated array) or as text (plain multidimensional array)
- Console
- Accessing arrays using notation data[0] versus data['x1'] versus data.x1