I was trying to create a line chart using d3 as shown here:
Pretty new to coding and have been completely stuck on where I am going wrong, google and youtube didn’t seem to have the answer either. My issue is with plotting data from a downloadable json. The rest of the code was tested with dummy data and seems to work. Here is the relevant portion:
// Parse the date / time
var parseDate = d3.time.format("%y%m%d").parse;
// Create a request variable and assign a new XMLHttpRequest object to it.
var request = new XMLHttpRequest()
// Open a new connection, using the GET request on the URL endpoint
request.open('GET', url, true)
request.onload = function () {
// Begin accessing JSON data here
var data = JSON.parse(this.response)
let dataY = []
let dataX = []
let i = 0;
data.reverse().forEach((dataset) => {
// console.log(dataset.values)
dataY[i] = dataset.values;
dataX[i] = dataset.date;
i++;
})
So this gets my data as my X dates and my Y values, and creates an array for the values of each. This works without error. Any time I try to take this further though, I run into errors.
I tried
function (d) { return { date: d3.timeParse(“%Y%m%d”)(d.dataX), value: d.dataY } },
I tried
function parseData(data){
var arr = []
for (var i in dataY.length()){
arr.push({
date: new dataX[i],
value : dataY[i]
}
)
return arr;
}
}
And lots of other stuff. Any help is super appreciated.
And I am happy to provide any further info needed!
Edit: I just realized that the page I saw this lesson on might have been a poster and not the official curriculum, if I should post this somewhere else, just let me know. Sorry!