type conversion through d3.json #3498
-
I am trying to complete an exercise presented by a Pluralsight course. In this course, (D3.js Data Visualization Fundamentals by Lars Verspohl), the instructor uses the following code to load data and uses the function: 'type' for type conversion of the the properties of the objects (parse strings to numbers, js date objects, NA to undefined, etc.). I believe the syntax he uses does not work for latest versions of d3. The other two things I am doing differently is: I am using d3.json rather than d3.csv and pulling from a mock API (though I could also use a file). Can someone tell me how to refactor the following code with the current version of d3? This is the code from the course (shortened object); it would log an array of json objects to the console with the types already modified:
Ftr: I did look up the new documentation and syntax tried it every possible way I could imagine, but I could never get any of the type conversion to work and log to the console the way it works in the course. I really appreciate any help anyone is able to provide!! I am a beginner so I apologize if I left any details out or don't know the correct terms; happy to fill in any more information that is needed. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
AFAIK CSV parsing needs type conversion because natively CSV is just strings. Instead, assuming your data is an array, you could just run |
Beta Was this translation helpful? Give feedback.
AFAIK
d3.json
doesn't provide type conversions because json is already typed; it's a thin veneer over the standard browser Fetch which has json parsing built in.CSV parsing needs type conversion because natively CSV is just strings.
Instead, assuming your data is an array, you could just run
res.map(type)
after receiving the json data...