0

I'm trying to load a .csv file into an array with objects, but for some reason my values are undefined.

My code:

file = ("data/" + country + ".csv")
console.log(file)
d3.csv(file, function(error, dataset) {                     
    var data = [];
    console.log(dataset)
    for (i = 0; i < dataset.length; i++) {
        var Period = {
                Year : dataset[i].Periods,
                numbers : dataset[i].numbers,
        }
        data.push(Period); 
    }
    console.log(data)               
    InitChart(data);                        
})

My csv looks like this:

Periods;numbers

"1998";"107"

"1999";"73"

"2000";"95"

"2001";"114"

"2002";"98"

"2003";"78"

"2004";"72"

"2005";"48"

"2006";"61"

"2007";"61"

"2008";"110"

1 Answer 1

3

What you have is not a comma separated values but a semicolon separated one. So you should use d3.dsv(';', file).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.