boson
boson

Reputation: 894

Undefined is not a function error d3js

I'm trying to load my own data into this d3.js visualization but I keep getting the error Undefined is not a function. The only difference is that, instead of defining freqData as they did, I defined mine to load from a data file

var freqData = d3.json("//sjs72/Users/ksdf/file.json", function(fdata) {
  console.log(fdata[0]);
});

It happens at the line

fData.forEach(function(d){d.total=d.freq.low+d.freq.mid+d.freq.high;});

Could anyone help me understand where I'm going wrong?

EDIT: The call I make is dashboard('#dashboard',freqData); The function dashboard takes the argument fData, which in this case I'm loading freqData into

Update:

I changed my variable definition and the resulting code looks like

var freqData;
  function doSomethingWithData() {
  console.log(freqData);
}

d3.json("//sjs72/Users/ksdf/file.json", function(dataFromServer)    {
  freqData = dataFromServer;
  doSomethingWithData();
}

dashboard('#dashboard',freqData);

But now I'm just getting the error

Uncaught SyntaxError: Unexpected identifier

On the last line of my script

Upvotes: 0

Views: 344

Answers (1)

HamsterHuey
HamsterHuey

Reputation: 1243

You are missing a closing parenthesis for your d3.json() call. That may very well be producing the issue for you. Corrected code:

var freqData;
  function doSomethingWithData() {
  console.log(freqData);
}

d3.json("//sjs72/Users/ksdf/file.json", function(dataFromServer)    {
    freqData = dataFromServer;
    doSomethingWithData();
  }
); // Added this here
dashboard('#dashboard',freqData);

Upvotes: 1

Related Questions