我需要增加已旋转的轴刻度标签的空间。下面的代码说明了,这里是working jsfiddle。这可能是使用crossfilter还是我们必须进入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;
}
答案 0 :(得分:4)
也可以用dc.js设置更大的底部边距:
pets_chart
.margins({ top: 10, left: 30, right: 10, bottom: 100 })
答案 1 :(得分:2)