2016-03-02 45 views
0

我有一個用例,我需要按字母順序對條形圖進行排序,我已經使用.ordering方法對一些條形圖進行了排序,但是它並不適用於按鍵排序。 這直流條形圖X軸按字母順序排序

bar 
    .margins({top: 20, left: 30, right: 10, bottom: config.xaxisorientation ? 60 : 20}) 
    .width(barWidth).height(barHeight) 
    .x(d3.scale.ordinal()) 
    .xUnits(dc.units.ordinal) 
    .brushOn(false) 
    .xAxisLabel(config.xaxislabel ? config.xaxislabel : '') 
    .yAxisLabel(config.yaxislabel ? config.yaxislabel : '') 
    .dimension(dim) 
    .renderLabel(true) 
    .renderType("group") 
    .title(titleAggre) 
    .elasticY(true) 
    .group(grp) 
    .valueAccessor(grpAggre); 

bar.yAxis().ticks(10).tickFormat(d3.format("s")); 

bar.ordering(function(a) { 
    return a.key.toLowerCase(); 
}); 

enter image description here

數據看起來是這樣的;

[{ 
    "c1": "profile", 
    "c2": "admin", 
    "c3": "e2e_mf", 
    "count:1 
    }, { 
    "c1": "profile", 
    "c2": "admin", 
    "c3": "aporec" 
    "count":2 
    }, { 
    "c1": "profile", 
    "c2": "admin", 
    "c3": "aporec", 
    "count":10 
    }] 
+0

你的數據是什麼樣的? – thatOneGuy

+0

@thisOneGuy,C3是dimesnion和度量組值[{ \t \t 「C1」: 「簡檔」, \t \t 「C2」: 「管理員」, \t \t 「C3」: 「e2e_mf」, 「測量」 :1 \t},{ \t \t 「C1」: 「簡檔」, \t \t 「C2」: 「管理員」, \t \t 「C3」: 「aporec」 \t},{ \t \t 「C1」 :「profile」, \t \t 「C2」: 「管理員」, \t \t 「C3」: 「aporec」, 「措施」:1 \t}] –

+0

確定,所以什麼是對左側的計數? – thatOneGuy

回答