Increase margins for rotated axis labels with Crossfilter

北城余情 提交于 2019-12-11 01:39:03

问题


I need to increase the space for axis tick labels that have been rotated. The code below illustrates, and here's a working jsfiddle. Is this possible with crossfilter or do we have to get into the d3?

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

回答1:


It's also possible to set bigger bottom margin with dc.js:

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

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




回答2:


It's possible with CSS:

.dc-chart svg {
  overflow: visible
}

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



来源:https://stackoverflow.com/questions/36593825/increase-margins-for-rotated-axis-labels-with-crossfilter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!