d3.js - Using d3 to read in information from a CSV file, how can i store values of a particular type into a variable? -
i have code reads information in csv file. information regarding road traffic accidents.
so code, can target values using 'd['weather conditions']' gives me -
which great! i'm looking store values of particular types in variables. e.g values equal 'fine without high winds' stored in array object 'var windy' or similar, there anyway go simply?
*update
any appreciated. thanks
right now, in code, printing console each weather condition encounter go on dataset row row.
if want group data based on weather conditions, can using d3.nest().
the example below uses simple json data show how can it. here, using d3.nest(), setting key weather condition , values object.
after structuring, data grouped, can check running script below: accidents rainy under key rainy , same other weather conditions.
var data = [{ "weather condition": "rainy", "property1": "val1", "property2": "val2" }, { "weather condition": "sunny", "property1": "val1", "property2": "val2" }, { "weather condition": "sunny", "property1": "val1", "property2": "val2" }]; // put snippet below in d3.csv function var expensesbyname = d3.nest() .key(function(d) { return d["weather condition"]; }) .entries(data); console.log(expensesbyname); <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script> 


Comments
Post a Comment