Access data
Next, we grab our data and create our accessor function (only one this time!)
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo set up the project on your local machine, please follow the directions provided in the README.md
file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.
This lesson preview is part of the Fullstack D3 Masterclass course and can be unlocked immediately with a single-time purchase. Already have access to this course? Log in here.
[00:00 - 01:06] Okay, great. So let's dig in. If we look at our checklist, we can see that our first step is to access our data. So look at the data structure and declare how to access these values we'll need . So if we go to our JavaScript file, remember that we want to grab this myweatherdata.json file. So let's create a data variable and use to theory.json to grab my weatherdata.json. And if you remember, this might take a minute to come back. So we'll want to put a wait here just to make sure that data exists before we continue on with our script. And then let's log it out to the console just to make sure we're getting what we think we're getting. This all looks great. And instead, let's log out the first data point because we know they're all the same. Now, this is where we create our accessor function.
[01:07 - 01:24] So in the past, we've created an x accessor, a y accessor. But for this chart, we really only have one metric. So, and that'll be on the x access. So, instead of both x and y, we really only need x here, at least for now.
[01:25 - 01:40] And we'll get more into that in a little bit. So x accessor. And we want to come back with the humidity value. So if we look at this object, we're just going to look to see what humidity is stored under.
[01:41 - 01:56] It's stored under humidity, which is what you might expect. So if we grab that and let's just log that out and move this console log statement down here.
[01:57 - 02:02] Okay, great. So it's 0.54. We have what we need and we're ready to get started with the second step.