0

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

3
  • Is that line you're saying the error occurs at inside the function within freqData? According to the error, fData is undefined. Put a breakpoint in and see what's going on. Commented Jan 11, 2017 at 17:51
  • Is it because you assign the data to freqData and then attempt to reference fData? Commented Jan 11, 2017 at 17:55
  • 2
    Your assumption is wrong: d3.json() is an asynchronous function, which does not return a value. See "Returning array from d3.json()". Commented Jan 11, 2017 at 18:09

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.