I am trying to read data from a csv file, and I want to store the data of each column in an array as in the code below. The problem that I get and I didn't know how to fix is that all the values are defined inside the brackets, but once I try to deal with the arrays else where, the data is undefined. Any ideas about what is going wrong? My version of D3 is v3.
<script>
var computerid = [];
var timestamp = [];
var percentage = [];
d3.csv("cpu-util.csv", function(data) {
for (var i = 0; i < data.length; i++) {
timestamp[i] = data[i].timestamp;
computerid[i] = data[i].Computer_ID;
percentage[i] = data[i].Percentage;
console.log(computerid[i]); //prints value
console.log(timestamp[i]);
console.log(percentage[i]);
}
});
console.log(computerid[1]); //here, it prints undefined although inside the loop it prints values
Part of the csv file:
Computer_ID, timestamp, value, Percentage
1, 01-07-11 0:00, 0.8, 8