Static dataset
Until now, every chart used a hardcoded array at the top of the file. Time to load real data from a local file (JSON or CSV) sitting next to your code.
Members only
5 minutes readOutline (draft)
- Hook: hardcoded arrays at the top of every chart file don't scale. Real projects keep data in its own file.
- The bundler trick: any modern bundler (Vite, Webpack, Next) imports JSON natively.
import data from "./data.json"and you have a typed array. - Loading CSV: import the raw text (Vite:
?rawsuffix) then parse withd3.csvParse(text). Result is an array of objects. - The string trap:
d3.csvParsealways returns strings. Coerce numbers and dates explicitly with+ornew Date()before passing to scales. - Project organisation: where to put a
/data/folder, how to share the dataset between charts. - When imports break down: bundle size, dynamic queries, data that changes daily. Bridge to the next lesson on fetching.
Oh no! ๐ฑ
This lesson isnโt available just yet.
Take a look at the status badges next to each lesson in the sidebar to see when itโs coming out.
Thanks for your patience! ๐