Graph C3 - JSON input

Does the C3 chart support JSON data? I'm trying to get a simple example working but couldn't find any documentation or examples on how to achieve something like this:

var chart = c3.generate({
    data: {
        type: 'bar',
        json: [
            { 'indicator': 'X', 'total': 100 },
            { 'indicator': 'Y', 'total': 200 },
            { 'indicator': 'Z', 'total': 300 }
        ],
        keys: {
            x: 'indicator',
            value: ['total']
        }
    },
    bar: {
        width: {
            ratio: 0.5
        }
    }
});

      

+3


source to share


1 answer


The problem was the lack of value axis

. Here is a working JS script .



var chart = c3.generate({
    data: {
        type: 'bar',
        json: [
            { 'indicator': 'X', 'total': 100 },
            { 'indicator': 'Y', 'total': 200 },
            { 'indicator': 'Z', 'total': 300 }
        ],
        keys: {
            x: 'indicator',
            value: ['total']
        }
    },
    axis: {
            x: {
                type: 'category'
            }
    },
    bar: {
        width: {
            ratio: 0.5
        }
    }
});

      

+4


source







All Articles