Looping in D3 using the d3.json method

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!

Answer №1

It could be a simple mistake in

beta; data[i].beta

it should actually be

beta: data[i].beta

Have you checked the console.log for any errors?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can we switch back to a partial view and return it as JSON?

I encountered a problem with my views, specifically the "index" and "_Track". I am trying to return my datalist to "_Track", which is a partial view. Can someone please assist me with this issue? The error message I received states: "for each statement can ...

Managing POST request data in Express: A step-by-step guide

Currently, I am facing an issue with my alert button on the client side, which has an event listener that is supposed to send data to the server. Below is the code snippet for the client side: alertBtn.addEventListener("click", () => { axios ...

Utilizing JSON with Express version 4.11 and the bodyParser middleware

I've been trying to figure this out for hours, searching through Stackoverflow and the internet in general. I've attempted different solutions but still can't seem to get it right. As a newcomer to node.js, I managed to follow a tutorial to ...

What is the best way to find specific data in a JSON file using SQL commands

Looking for a way to search JSON data where in json like {"buyer_uni_no":{"info":[],"Pos":[[0,0,0,0]]}} I've attempted the following SQL queries, but they were unsuccessful. select * from test where JSON_VALUE(myjson,'$.buyer_uni_no.info&apos ...

The information returned to the callback function in Angular comes back null

In my Node.js application, I have set up an endpoint like this: usersRoute.get('/get', function(req, res) { //If no date was passed in - just use today's date var date = req.query.date || dateFormat(new Date(), 'yyyy-mm-dd&ap ...

Rotation of objects using Three.js on a spherical surface

I have successfully implemented a particle system to evenly distribute points on a sphere and then place instances of a given geometry on those points. Now, I am looking to rotate those geometries to match the surface angle of the sphere. Below is the cur ...

Clicking on the ActionButton will trigger the sending of an HTTP Request in this Firefox

Seeking guidance: As I develop an addon, my objective is to initiate a HTTP request upon clicking the ActionButton. The data to be sent to the server includes the URL of the tab and the content of the page. Initially, I attempted to create a log message a ...

What is the best way to apply dynamic wrapping of a substring with a component in Vue.js?

My Objective My goal is to take a user input string and render it with specific substrings wrapped in a component. Specifically, I am looking to identify dates within the string using a regex pattern and then wrap these dates in a Vuetify chip. Progress ...

Why is React's nested routing failing to render properly?

click here for image portrayal I am currently attempting to integrate react router, specifically a nested router. However, when I click the links on the contact page, no results are being displayed. Any assistance would be greatly appreciated. For more in ...

Steps to design a unique input radio button with embedded attributes

In my current project, I am utilizing react styled components for styling. One issue that I have encountered is with the text placement within a box and the need to style it differently when checked. What have I attempted so far? I created an outer div a ...

There was an issue parsing the parameter '--request-items' due to invalid JSON format. Decoding failed as no JSON object could be found

My current environment includes AWS cloud, DynamoDB, AWS Cloud9, Python, and JSON. I'm attempting to write these elements into a DynamoDB table using the command aws dynamodb batch-write-item --request-items file://Sensors.json in my Cloud9 CLI. How ...

Website header extends beyond normal boundaries, exceeding 100% width

Here is the CSS code I used for styling the header: #header { font-size: 3rem; width: 100%; height: 4.5em; display: flex; align-items: center; padding-left: 1em; } Despite setting it to 100% width, on the website it displays with a ...

Navigating JSON Levels in Swift with Codable

I am interested in utilizing the Pokémon API to retrieve data and transform it into a Swift Pokemon structure. Upon fetching information for Pokemon #142, here is a snippet of the response received: { "id": 142, "name": " ...

A guide to building your own live HTML editing tool

I'm currently developing a PHP website that allows users to enter text into a textarea, and have the input displayed in a table in real time for a preview of the result. I am seeking guidance on how to make this feature possible. I have come across w ...

What could be the reason for the absence of this Javascript function in my attribute?

I have been working on an app using electron, and I have a function that successfully adds tabs to the app. The issue arises when I try to add tabs via JavaScript with the onclick attribute - they show up as expected but do not execute the code to hide and ...

Flattening an array of Map in Typescript involves combining all the

I am working with an array containing entries of type Map<string, number> Is there a way to flatten this array into a single map? Map<string, number>[] converted to Map<string, number> Appreciate any help on this matter. ...

Retrieving dates from a database and populating them into a jQuery UI Picker using PHP

I need to retrieve dates from the database using PHP and highlight them in a datepicker. Here is how I am attempting to accomplish this: HTML Date: <input type="text" id="datepicker"> // Static dates // An array of dates var eve ...

What are the steps to send AJAX data before closing the page?

Trying for over 7 hours to send a value to the database when the user closes the page, like online and offline. Still struggling to find a working solution. <script tysssspe="text/javascript"> //ST window.onbeforeunload = function(){ var user_st = ...

Updating the value within the render() function in React - a guide

I am struggling to display the data retrieved from the websocket in my application. The render function is not updating even after receiving data from the socket. I tried to update the state with this.state when new data arrives from the websocket, but it ...

Having trouble understanding why the other parts of my header are not displaying

<head> This special function runs when the webpage is loaded. <body onload="myOnload()"> A distinctive div at the top with a unique graphic <div id="header"> <img src="resumeheader.png" alt="Header" style="width:750px;h ...