最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - C3 bar chart - JSON input - Stack Overflow

programmeradmin1浏览0评论

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
        }
    }
});

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
        }
    }
});
Share Improve this question edited Oct 23, 2014 at 2:54 armandino asked Oct 23, 2014 at 2:21 armandinoarmandino 18.6k17 gold badges74 silver badges85 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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
        }
    }
});
发布评论

评论列表(0)

  1. 暂无评论