Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C3 bar chart - JSON input

Does the C3 bar chart support JSON data? I am trying to get a simple example working but could not 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
        }
    }
});
like image 508
armandino Avatar asked Oct 23 '14 02:10

armandino


1 Answers

Problem was the missing axis value. Here is a working JS fiddle.

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
        }
    }
});
like image 190
armandino Avatar answered Sep 30 '22 00:09

armandino