My d3.json code was functioning perfectly until I added this for loop to it. In the code, I am constructing the patientList object which consists of a list of patient names with each patient having an array of appointment dates and alpha beta values. The database contains multiple rows for each patient where the name and alpha beta values are constant but the dates vary. Hence, this for loop is essential to organize the information with the name as the primary key. However, since I am new to working with d3 and JavaScript, I'm unable to pinpoint the issue in my code.
var data;
var patientList = {};
d3.json("data.php", function(error, json) {
if (error) return console.warn(error);
data = json;
for(var i = 0; i < data.length; i++) {
var name = data[i].name;
if(!patientList[name]) {
var newPatient = {
dates: data[i].date,
alpha: data[i].alpha,
beta: data[i].beta
};
patientList[name] = newPatient;
} else {
patientList[name].dates.push(data[i].date);
}
}
alert("Hello," + data[3].name);
});
Any recommendations or insights on how to resolve this issue would be greatly appreciated.
Thank you in advance!