【发布时间】:2016-12-14 13:22:13
【问题描述】:
我想根据条形图上出现的条形数量调整条形图的宽度。这是我的图表,它显示了足够的记录,这些记录适合宽度并且显示得很好。
这是另一种情况,其中只有两个条以相同的宽度显示,这看起来很奇怪。
对于这种情况,我需要根据柱的数量来调整图表的宽度,这样我的图表就会看起来很漂亮。
这是我的脚本的一部分
var width = ??; // Here how should I calculate width based on the number of bars?
redrawCustomerCodeBarChart
.width(width)
.height(400)
.margins({top: 10, right: 10, bottom: 70, left: 30})
.dimension(customerNamer)
.group(customerNameGroupr)
.x(d3.scale.ordinal().domain(newCoh.map(function (d) {return d.customerName; })))
.xUnits(dc.units.ordinal)
.elasticY(true)
.renderHorizontalGridLines(true)
.on('renderlet',function(chart){
chart.selectAll("g.x text")
.attr('dx', '-15')
.attr('transform', "rotate(-55)");
})
.on('filtered.monitor', function(d) {
// return d.key + ' (' + d.value + ')';
if(d.value !== undefined)
size= d.value;
})
.controlsUseVisibility(true);
【问题讨论】:
-
在这种情况下我们可以使用
.valueAccessor或.keyAccessor来返回键值对 -
感谢您的想法