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]);
});
Leave a Reply