Skip to content Skip to sidebar Skip to footer

How To Pass Javascript Object To Another Function?

I am downloading csv file from AWS S3 bucket so that I can use it in D3. No problem downloading the csv file. In code below the console.log(data.Body.toString()) prints out the csv

Solution 1:

After reading a the docs on d3.csv, it loads a CSV file from a URL, but in your example, you've already loaded the data, you just need to parse it. So d3.csv isn't going to be of any use.

It looks like the D3 function for parsing is d3.csv.parse(data) which will return an array of parsed data. (Docs are here)

So you could do something like…

var bucket = newAWS.S3();
var mergedcsv;

bucket.getObject({
    Bucket: 's3-google-analytics', 
    Key: 'merged.csv'
}, 
    functionawsDataFile(error, data) {
        if (error) {
            returnconsole.log(error);
        }
        mergedcsv = d3.csv.parse(data.Body.toString()); 

        // now mergedcsv will be an array, so you can do whatever you were going to do with it before, i.e...var parseDate = d3.time.format("%Y%m%d").parse;
        var counter = 0;
        data.forEach(function(d) {
           etc
        });
    }
);

Post a Comment for "How To Pass Javascript Object To Another Function?"