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

Unable to create chart with json and dot in key #1691

Closed
DoomyTheFroomy opened this issue May 10, 2016 · 12 comments · Fixed by #2761 · May be fixed by saadcss/ionic-site#3
Closed

Unable to create chart with json and dot in key #1691

DoomyTheFroomy opened this issue May 10, 2016 · 12 comments · Fixed by #2761 · May be fixed by saadcss/ionic-site#3

Comments

@DoomyTheFroomy
Copy link

I have tried to create a donut chart for Chrome version. Which contain a dot as key. This will cause errors. I have tried to create the chart on http://c3js.org (c3.min-4c5bef8f.js) with a chrome (50.0). But it was not possible.
bildschirmfoto 2016-05-10 um 13 43 58

var chart = c3.generate({
    data: {
        json: [
            {'38.0': 10, '46.0': 10, '47.0': 10, '49.0': 20, '50.0': 30, 'unbekannt': 4}
        ],
        keys: {
            value: ['38.0', '46.0', '47.0', '49.0', '50.0', 'unbekannt']
        },
        type : 'donut'
    },
    donut: {
        title: "Chrome Versions"
    }
});
@Kyhel
Copy link

Kyhel commented May 11, 2016

I encountered the same problem today.
I've done some research and found the culprit code.

In the function c3_chart_internal_fn.convertJsonToData, since the version 0.4.11 (the problem doesn't exist in version 0.4.10), the following block of code changes :

0.4.10
targetKeys.forEach(function (key) {
                    // convert undefined to null because undefined data will be removed in convertDataToTargets()
                    var v = isUndefined(o[key]) ? null : o[key];
                    new_row.push(v);
                });

becomes

0.4.11
targetKeys.forEach(function (key) {
                    // convert undefined to null because undefined data will be removed in convertDataToTargets()
                    var v = $$.findValueInJson(o, key);
                    if (isUndefined(v)) {
                        v = null;
                    }
                });

I'm not exaclty sure what the findValueInJson does, but the part replacing brackets with dots and then spliting on the dots seems to be the cause of problems.

Anyway, until this issue is resolved, using the 0.4.10 version solved it for me.

Cheers,
Kyhel

@DoomyTheFroomy
Copy link
Author

@Kyhel thank you very much! So I can use it, until the issue has been fixed!

@kelthuzad
Copy link
Contributor

kelthuzad commented May 12, 2016

This was implemented as a fix for issue #1471 .
The problem is, that the syntax "x.y" is now interpreted as "get value of key y which is inside the object that is accesed by key x" and not "get value of key "x.y".

A bugfix would probably be to check if key "x.y" exists and using its value if it does. Only if this key doesn't exist, the nested-object logic should be used.

A workaround would be if your object structure would look like this:

json: [ {'38':{'0': 10}, '46':{'0': 10}, '47':{'0': 10}, '49':{'0': 20}, '50':{'0': 30}, 'unbekannt': 4} ],

@joeshub
Copy link

joeshub commented May 12, 2016

Has anyone created a jsfiddle of how the new x.y data model fetch is supposed to work? This would be really helpful.

@kelthuzad
Copy link
Contributor

kelthuzad commented May 12, 2016

@joeshub This is a simple jsfiddle that demonstrates the new functionality: http://jsfiddle.net/h0wag7ur/

@kelthuzad
Copy link
Contributor

kelthuzad commented May 12, 2016

Fixed the bug (see pull request), this jsfiddle shows @DoomyTheFroomy 's example with my fixed c3 dependency.
Sorry for the inconvenience due to this bug :-(

Edit:
This bugfix only fixes a key containing a . or [] in the first level of the object. All keys in nested objects may not contain . or [].

@Kyhel
Copy link

Kyhel commented May 13, 2016

Thanks for the explanations, now I understand better what was the reason behind the new code.
However, I think allowing nested objects keys with the dot notation a bit strange, because of the conflict with decimal numbers.
But you probably can't satisfy everyone at the same time anyway.

Good job on fixing that quickly anyway, and thanks for your work on c3 !
Cheers,
Kyhel

@kelthuzad
Copy link
Contributor

A check to see if a key is a number could be implemented to prevent the conflict with numbers.
Another possibility would be to choose another character instead of "." to reference inner objects.

But I don't know if it's worth it. I don't like the idea of implementing overly complex logic checks or obscure special characters.

@scherrs
Copy link

scherrs commented Dec 18, 2019

It seems that this issue is still open in the current version, isn't it?

We have a problem similar to the described behavior.

@svki0001
Copy link

svki0001 commented Dec 19, 2019

The problem is still in the latest version.

@1Jesper1
Copy link

1Jesper1 commented Jan 7, 2020

How to fix this problem?

@miladtai
Copy link

I have this problem too, how we can solve this ?

kt3k added a commit that referenced this issue Feb 26, 2020
Co-authored-by: Jakob Kneissl <[email protected]>
@kt3k kt3k mentioned this issue Feb 26, 2020
kt3k added a commit that referenced this issue Feb 26, 2020
Co-authored-by: Jakob Kneissl <[email protected]>
kt3k added a commit that referenced this issue Feb 26, 2020
Co-authored-by: Jakob Kneissl <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants