我想根據條形圖上顯示的條數來調整條形圖的寬度。這是我的圖表,它顯示了足夠寬度的記錄,並且很好地顯示。 計算dc.js中條形圖中的條數
這裏是另一種情況,其中只有兩個條以相同的寬度顯示,看起來很奇怪。
對於這種情況,我需要根據酒吧的數量調整圖表的寬度,以便我的圖表看起來很漂亮。
這裏是我的腳本
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'來返回鍵值對 – ashishraaj