Divide Large Data Set into Smaller Data Sets
US Rainfall by State part 2 — divide large data set into 5 separate data sets
Previous Lesson
Remove Characters from Beginning of JavaScript String
Overview
There are 50 states in the data. Graphing the 50 states on a single graph will make the graph difficult to read. We will divide the one large data set you built in the previous lesson into 5 separate data sets.
In a future lesson, we will create clickable buttons to change between the data sets.
Demo of Completed Project
https://codetricity.github.io/codecakes-rainfall/index.html
Code for This Lesson
https://github.com/codetricity/codecakes-rainfall/blob/master/lessons/02/js/main.js
Steps
Create new code in the d3.csv
promise. Put it after the code you built in the previous lesson to clean the data.
Create 5 empty arrays.
Loop through data array and populate each array with rainfall data from 10 states.
Bundle arrays into into one larger array called, datasets
.
Use console.log to print out datasets.
console.log(datasets);