I am trying to read a simple CSV file which is "employee.csv"
:
Name, Age
Janik, 24
Jakob, 45
Anna, 30
Niklas, 35
The D3 script that I have to attempt this "employee.csv"
file is as follows:
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8"/>
<title>Loading CSV file in D3</title>
<script src = "./d3/d3.min.js"></script>
</head>
<body>
<script>
d3.csv("./employee.csv", function(data)
{
for(var i = 0; i < data.length; i++)
{
console.log(data[i]);
//console.log(data[i].Name);
//console.log(data[i].Age);
}
});
</script>
</body>
</html>
This outputs each line from the CSV file. However, if I try to access each of the values from Age
column, using the line
console.log(data[i].Age);
It gives the output undefined
for each of the rows, whereas the the names are read fine
console.log(data[i].Name)
What am I doing wrong?