2013-04-26 52 views

回答

1

我不確定你試過這麼胖,但here中的例子非常簡單。

.showValues(true)幾乎沒有訣竅。

希望它有幫助。

+0

感謝兄弟..但我是試圖讓這個工作在一個多條形圖上..我現在已經編輯了這個問題,明確提到這一點。 – azi 2013-04-26 12:00:05

+0

@azi - 您是否嘗試將該行添加到多條形圖中?到目前爲止你做了什麼? – shabeer90 2013-04-26 12:02:32

+0

是的,我沒有嘗試..沒有工作...我有多條條形圖工作生產..只是想顯示在頂部的值...沒有找到任何參考任何地方...所以天堂沒有嘗試過任何東西(除了你的建議) – azi 2013-04-26 12:12:37

4

重複的How to display values in Stacked Multi-bar chart - nvd3 Graphs

有一個修復程序,你可以在https://gist.github.com/topicus/217444acb4204f364e46

編輯自己實現:複製的代碼,如果GitHub的鏈接被刪除:

// You need to apply this once all the animations are already finished. Otherwise labels will be placed wrongly. 

d3.selectAll('.nv-multibar .nv-group').each(function(group){ 
    var g = d3.select(this); 

    // Remove previous labels if there is any 
    g.selectAll('text').remove(); 
    g.selectAll('.nv-bar').each(function(bar){ 
    var b = d3.select(this); 
    var barWidth = b.attr('width'); 
    var barHeight = b.attr('height'); 

    g.append('text') 
     // Transforms shift the origin point then the x and y of the bar 
     // is altered by this transform. In order to align the labels 
     // we need to apply this transform to those. 
     .attr('transform', b.attr('transform')) 
     .text(function(){ 
     // Two decimals format 
     return parseFloat(bar.y).toFixed(2); 
     }) 
     .attr('y', function(){ 
     // Center label vertically 
     var height = this.getBBox().height; 
     return parseFloat(b.attr('y')) - 10; // 10 is the label's magin from the bar 
     }) 
     .attr('x', function(){ 
     // Center label horizontally 
     var width = this.getBBox().width; 
     return parseFloat(b.attr('x')) + (parseFloat(barWidth)/2) - (width/2); 
     }) 
     .attr('class', 'bar-values'); 
    }); 
});