Skip to content

Instantly share code, notes, and snippets.

@codetricity
Last active September 16, 2018 16:55
Show Gist options
  • Select an option

  • Save codetricity/fdc62d20a333700bca0bb5adf2d208b6 to your computer and use it in GitHub Desktop.

Select an option

Save codetricity/fdc62d20a333700bca0bb5adf2d208b6 to your computer and use it in GitHub Desktop.
use d3.csv to get data from file

Temp by Month 2 - Get Data from File

Section Goal

Read in data from csv file and make it usable in your program.

Learning Objectives

  • Understand CSV format
  • Understand array format
  • Understand JavaScript object format
  • Understand JavaScript promise syntax
  • Be able to use d3.csv

Steps

  1. Data is stored on a Google Sheet

  2. Download as CSV

    File -> Download as -> Comma-separated values

    Imgur

  3. Use d3.csv to convert from csv to array of javascript objects

The previous project used an online conversion tool.

This project uses d3 to read in the csv file and convert the file into an array of objects.

New versions of d3 use the JavaScript promise .then keyword.

  d3.csv("city-month.csv").then(function(dataInFunction){
         console.log(dataInFunction);
  });

JSON output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment