1

Huge thank you in advance, I am new to D3. I am trying to make a multiline chart, I have a single line chart coded up that I am trying to transition to a multiline chart. I have data that looks like:

country,year,average
United States,1972,54
United States,1973,56
United States,1974,53
United States,1975,57
United States,1976,60
Brazil,1972,24
Brazil,1973,21
Brazil,1974,25
Brazil,1975,26
Brazil,1976,24
South Africa,1972,17
South Africa,1973,18
South Africa,1974,19
South Africa,1975,21
South Africa,1976,25

This data goes on to include other countries. What I would like to do is nest this by country in order to create a line for each country.

My code:

var parseTime = d3.timeParse("%Y"); 

function rowConverter(data) {
    return {
        country : data.country, 
        year : parseTime(data.year),
        average : +data.average // the + operator parses strings into numbers
    };
d3.csv("EvenMore.csv", rowConverter, function(data) {

    var countries = d3.nest()
        .key(function (d) { return d.country; })
        .entries(data); 

    console.log(countries); 

The console looks like:

console

amandaraen
  • 23
  • 5

0 Answers0