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

Load JSON into Donut Chart #430

Closed
virginiatong517 opened this issue Jul 8, 2014 · 3 comments
Closed

Load JSON into Donut Chart #430

virginiatong517 opened this issue Jul 8, 2014 · 3 comments

Comments

@virginiatong517
Copy link

Your example shows how to load data from JSON into a line chart, however, pie and donut charts have slightly different column input, as there is only one column only contains one value. How would I go about loading an array of JSONs of the following format:

var test_array_JSONs = [
{"label": "Label 1", "amount": 20},
{"label": "Label 2", "amount": 50},
{"label": "Label 3", "amount": 30}
];

into a donut chart?

I tried the following code but it unfortunately doesn't work:

var donutChart = c3.generate ({
data: {
json: 'test_array_JSONs',
keys: {
x: 'label',
value: 'amount'
},
type: 'donut'
}
});

Please let me know if it's possible to do this, thank you!

@virginiatong517
Copy link
Author

Actually, I haven't seen an example when you can pass in a json stored in a variable into data. Is this possible?
For example:
var x = a json object, or an array of json objects
data: {
json: 'x'
}

@virginiatong517
Copy link
Author

Additionally, how do you unload a json object?

@masayuki0812
Copy link
Member

Hi, I think this is what you want to do. http://jsfiddle.net/hQSSn/3/
For unload, please specify the ids (in your case, Label 1, Label 2, etc) as the fiddle.

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

No branches or pull requests

2 participants