0

I'm trying to pass JSON data (from an AJAX call) into a function that uses D3 charts to iterate through the data. I am NOT passing the URL to a Json file, I am passing the DATA from a Json that is returned from an AJAX call. Every time I do this, however, the 'data' in the callback is undefined and won't let me iterate through it. How do I manage this? I just want to iterate through the JSON data and draw things according to it.

Here's the example code:

drawLine(jsonData)

function drawLine(chartData) {
    d3.json(chartData, function(data) {
        data.forEach(function(d) {
            d.date = parseDateD3(d.date);
            d.close = +d.close;
        });

    // DO STUFF PAST HERE TO DATA

    });
}

1 Answer 1

2

You only need to use d3.json if you're actually doing an AJAX call. If you have the data already, the code should look like this.

function drawLine(data) {
    data.forEach(function(d) {
        d.date = parseDateD3(d.date);
        d.close = +d.close;
    });

  // DO STUFF PAST HERE TO DATA
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.