First you need to create the query that gives you the data to put into javascript. I have created a query here that selects birdstrikes from 1992 that happened during the day from a dataset containing all incidents where birds hit airplanes
Now open the JSON file in any editor you have. Visual studio code, Webstorm, as long as you open the file. Select all (cmd + a or ctrl + a) the and copy the text (cmd + c or ctrl + c)
Get the data into javascript
First create a new project in Webstorm with 3 files:
index.html
main.js
data.js - this file will only contain your data!
The index.htmlshould look like this:
Notice that the data.js file is loaded before the main.js. If there are global variables in the data.js we can reach them in the main.js file!
The main.js should look like this
data.js
The data.js file is the file that will contain your data. First you create a new variable called data as let. Assign it to be a string literal with the backticks
Now inside the backticks you paste the copied json!
It will look weird! Something like this:
We have now taken the json from workbench and copied it into a string in javascript. But we can't use a string for anything, we need the array of objects so we can create out graphs! To do that scroll all the way to the bottom of the script. Now write the following lines:
This will transform the string that contained all the JSON into an array of objects!
Now open the html page, jump into the inspector and hopefully you will see the array of objects logged out!