直流条形图x轴按字母顺序排序

时间:2016-03-02 13:35:09

标签: sorting d3.js dc.js

我有一个用例,我需要按字母顺序排序条形图,我已经使用.ordering方法对一些条形图进行了排序,但它不能从密钥排序中工作。 此

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
  }]

1 个答案:

答案 0 :(得分:0)

这看起来像这个错误:

https://github.com/dc-js/dc.js/issues/772

已在dc.js 2.0 beta 6中修复。您是否可以使用早期版本?

我不确定1.7。*版本中是否存在该错误。

相关问题