C3 chart with JSON data C3 chart with JSON data json json

C3 chart with JSON data


You have to format your json response to fit the expected format of C3 for Donut graph type.

function OnSuccess(response) {    var data = {};    var value = [];    JSON.parse(response).forEach(function(d) {        data[d.item1] = d.y;        value.push(d.item1);    });    c3.generate({                data: {                    json: [data],                    keys: {                        value : value                    },                    type: 'donut'                },                donut: {                    title: "Approval",                    width: 40,                    label: {                        show: false                    }                },                color: {                    pattern: ["#ff9800", "#78c350", "#f7531f"]                }        })}

Your server will normally output a string, so using a JSON.parse will transform this string into a json object.


function OnSuccess(response) {    var jsonData = response.d;    var chart = c3.generate({        bindto: '#chart-var-project',        data: {            json: JSON.parse(jsonData),        }    });}