Day 100 of 180 Days of Data Viz Learning #jfdi

I’m doing some form of data visualization learning for 180 days because I need to #JFDI.

See post explaining how and why I’m doing this.

Code Learning:

Learn JS Reading Data 
Three Takeaways:

  • When loading CSVs and other flat files, you have to do the type conversion, or else numbers will come in as strings. A simple way to do this is to use the + operator (unary plus).
  • forEach can be used to iterate over the data array.
  • Dot notation is a useful way to access the properties of these data objects. However, if your headers have spaces in them, then you will need to use bracket notation as shown below.
  • d3.csv(“/data/cities.csv”, function(d) {
    return {
    city : d.city,
    state : d.state,
    population : +d.population,
    land_area : +d[“land area”]
    };
    }, function(data) {
    console.log(data[0]);
    });

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s