C3JS bar chart with specific order

前端 未结 1 625
情书的邮戳
情书的邮戳 2021-02-13 20:08

If I have a C3JS grouped bar chart defined like the following, how can I get the segments to stay in the order I\'ve defined them instead of in ascending order by value? By def

1条回答
  •  南方客
    南方客 (楼主)
    2021-02-13 20:58

    C3js documentation has page for this : http://c3js.org/samples/data_order.html

    You can order your data in following way :

    var chart = c3.generate({
        data: {
            columns: [
                ['data1', 130, 200, 320, 400, 530, 750],
                ['data2', -130, 10, 130, 200, 150, 250],
                ['data3', -130, -50, -10, -200, -250, -150]
            ],
            type: 'bar',
            groups: [
                ['data1', 'data2', 'data3']
            ],
            order: 'desc' // stack order by sum of values descendantly.
    //      order: 'asc'  // stack order by sum of values ascendantly.
    //      order: null   // stack order by data definition.
        },
        grid: {
            y: {
                lines: [{value:0}]
            }
        }
    });
    

    Also detailed explanation here too : http://c3js.org/reference.html#data-order

    You can specify your function too :)

    0 讨论(0)
提交回复
热议问题