Rakesh
Rakesh

Reputation: 57

queue.js pass data from local variable not from external file

I want to pass the data using a json variable. In the below example the json is fetched from an external JSON file. can any one help me how to pass the data from a local variable as i am new to dc.js

queue()
    .defer(d3.json, "sampledata.json") // sampledata.json  is an external json file
    .await(makeGraphs);

function makeGraphs() {
   //function which proceses the data
}

i tried this

var sampledata = [ ....];
queue().defer(d3.json, "sampledata.json") // sampledata.json  is an external json file
        .await(makeGraphs);

    function makeGraphs() {
       //function which proceses the data
    }

but did not work.

Upvotes: 2

Views: 474

Answers (1)

Gerardo Furtado
Gerardo Furtado

Reputation: 102198

If you have a local variable it makes no sense using an asynchronous call to pass it. Just pass it straight away as an argument:

var sampleData = [...];//this is your data

makeGraphs(sampleData);//call your function using it as an argument

And then:

function makeGraphs(data){//this is the parameter
     //use 'data' here
}

Upvotes: 2

Related Questions