2016-12-01 54 views
0

我遵循參考和this answer的說明,但沒有成功。C3堆疊圖表維護數據訂單

我有一個堆疊的條形圖,我希望堆棧中的數據以它在數據中的順序出現,但它得到了重新排序,我無法弄清楚如何防止它。

這裏是jsfiddle

下面的代碼

var chartOptions = { 
    element: 'chart', 
    data: { 
    "rows":[["0-1","2-3","4-5","6","7"],[25,56,14,2,1],[6,66,27,0,0],[0,70,30,0,0],[27,54,14,5,0],[0,54,30,8,8],[29,64,7,0,0]], 
    "type":"bar", 
    "groups":[["0-1","2-3","4-5","6","7"]], 
    "order":null 
    }, 
    axis: { 
    "x":{ 
     "type":"category", 
     "categories":["Whole List","committed","community","congregation","core","crowd"] 
    }, 
    "y":{ 
     "padding":{ 
     "top":0 
     } 
    } 
    }, 
    stacked: true, 
    size: {"height":300} 
} 

var chart = c3.generate(chartOptions); 

我想該系列是在爲了0-1,2-3,4-5,等等

回答

0

事實證明這是一個known issue。如果任何一個標題是一個整數(或一個整數的字符串),那麼c3將對列進行排序。

解決方法我將一個空格添加到列名的末尾,以便c3將它們解釋爲字符串而不是數字。

chartOptions['data']['rows'][0] = ["0-1","2-3","4-5", 
            "6 ", "7 "]; // Spaces appended to these 
chartOptions['data']["groups"] = [["0-1","2-3","4-5","6 ", "7 "]]; 

我的jsfiddle與解決方法更新。