使用Crossfilter增加旋转轴标签的边距

时间:2016-04-13 09:16:21

标签: d3.js dc.js crossfilter

我需要增加已旋转的轴刻度标签的空间。下面的代码说明了,这里是working jsfiddle。这可能是使用crossfilter还是我们必须进入d3?

See how x-axis tick labels are cut off..

HTML

<script src="https://rawgit.com/square/crossfilter/master/crossfilter.js"></script>
<script src="https://d3js.org/d3.v3.js"></script>
<script src="https://rawgit.com/dc-js/dc.js/develop/dc.js"></script>

<span>
  <div id="petchart"></div>
</span>

JS

j = [{'pet': 'Felis catus'}, {'pet': 'Canis lupus familiaris'}, {'pet': 'none'}, 
        {'pet': 'Felis catus'}, {'pet': 'Melopsittacus undulatus'}, 
    {'pet': 'Canis lupus familiaris'}, {'pet': 'Canis lupus familiaris'}];

cf = crossfilter(j);
pets_chart = dc.barChart("#petchart");
petDimension = cf.dimension(function(d) {return d.pet;});
petCountGroup = petDimension.group();

pets_chart
  .dimension(petDimension)
  .group(petCountGroup)
  .x(d3.scale.ordinal().domain(["Felis catus","Canis lupus familiaris","Melopsittacus undulatus","none"])) 
  .xUnits(dc.units.ordinal)
    .width(300).height(250)
  .colors(['#1f77b4']).colorAccessor(function(d, i){ return i; })
  .xAxis().ticks(2);

dc.renderAll();

CSS

g .x.axis text {
    text-anchor: end !important;
    transform: rotate(-45deg);
    font-size: 0.7em;
}

2 个答案:

答案 0 :(得分:4)

也可以用dc.js设置更大的底部边距:

pets_chart
   .margins({ top: 10, left: 30, right: 10, bottom: 100 }) 

https://jsfiddle.net/LukaszWiktor/fts3tevj/

答案 1 :(得分:2)

CSS可以实现:

.dc-chart svg {
  overflow: visible
}

https://jsfiddle.net/LukaszWiktor/70jx74c5/