Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json method not working on newest version.. #20

Closed
gungunfebrianza opened this issue Apr 12, 2018 · 5 comments
Closed

json method not working on newest version.. #20

gungunfebrianza opened this issue Apr 12, 2018 · 5 comments

Comments

@gungunfebrianza
Copy link

gungunfebrianza commented Apr 12, 2018

i use this script to open my json file..

function load(){ // <-E
    d3.json("data.json", function(error, json){ // <-F
        data = data.concat(json);
        render(data);
    });

when i tried to debug this is success if use D3.js version 3.2.8 but when iam changing to D3.js version 5 is not working. need help to solve this one.

here is the source :
styles.zip

@mbostock
Copy link
Member

Please read the CHANGES:

https://github.com/d3/d3/blob/master/CHANGES.md#changes-in-d3-50

Please use Stack Overflow tag d3.js to ask for help. Stack Overflow provides a better collaborative forum: thousands of D3-related questions have been asked there, and some answers may be relevant to you.

When asking for help, please include a link to demonstrate the issue, preferably as an Observable notebook. It is often impossible to debug from code snippets alone. Isolate the issue and reduce your code as much as possible before asking for help. The less code you post, the easier it is for someone to debug, and the more likely you are to get a helpful response.

If you have a question about D3’s behavior and want to discuss it with other users, also consider the d3-js Google Group or joining the d3-js Slack.

Thank you! 🤗

@gungunfebrianza
Copy link
Author

Thanks for your time coming here help my question. I learn a lot data visualization from D3.js. This is the best framework i ever try since i want the flexibility. Your innovation in data visualization is the best contribution to the society.

currently to learn I am following the book : Data Visualization with D3.js Cookbook by Nick Qhi Zu. Published in 2013. so i guess i get the old d3.js version. Okay later i will use stackoverflow and joining the group :)

I love to share, prof.

@cheshirekow
Copy link

The problem with pedantically not answering someone's question is that you inevitably end up as the first google search result.

  • There is no mention of this change in CHANGES.md on master. Perhaps you meant a specific commit?
  • There is no answer on stack overflow
  • The current API Documentation does not explain what the second parameter does, or what the function returns

I believe the answer is that the json function now returns a promise, so change your code from:

d3.json("data.json", function(error, json){
        data = data.concat(json);
        render(data);
    });

to

d3.json("data.json").then(function(json){
        data = data.concat(json);
        render(data);
    });

@mbostock
Copy link
Member

@cheshirekow, the answer is the very first change described in the linked CHANGES document, starting with “D3 now uses Promises instead of asynchronous callbacks to load data…” and immediately followed by code snippets that exactly describe how to turn a v4-style callback into a v5 promise. The only difference is that it’s using d3.csv rather than d3.json, but all the d3-fetch methods behave the same way.

@BJWiley233
Copy link

New SO post https://stackoverflow.com/questions/49768165/code-within-d3-json-callback-is-not-executed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants