2016-09-21 31 views
0

我正在使用nvd3 stackedgroupchart,現在我已將單個X-Axis列標籤更改爲多個。 另外我需要爲月份名稱添加輔助X-Axis。我正在使用下面的鏈接nvd3 dual-axis in stackedgroupedChart

http://bl.ocks.org/4629518

現在我的圖表顯示一樣, enter image description here

,我需要在X軸這樣添加個月的圖表,

enter image description here

現在我的X-Axis根據以下代碼生成:

var xScale = d3.scale.ordinal() 
    .domain(d3.range(dataset.length)) 
    .rangeRoundBands([0, width], 0.8); 

var xAxis = d3.svg.axis() 
    .scale(xScale) 
    .tickFormat(function(d) { return dataset[d].shift; }) 
    .orient("bottom"); 

請幫忙添加輔助標籤X軸,

由於事先

回答

1

創建首選標另一軸映射

  • 使用copy的功能來複制規模
  • 將新的域值添加到比例尺
  • 創建新座標軸並添加比例尺
  • 呼叫(axisNew)和改變變換值

    var x2 = x0.copy(); 
        x2.domain(["a","b","c","d"]); 
    
    var xAxis1 = d3.svg.axis() 
        .scale(x2) 
        .tickSize(0) 
        .orient("bottom"); 
    
    svg.append("g") 
        .attr("class", "x axis") 
        .attr("transform", "translate(0," + (height+10) + ")") 
        .call(xAxis1); 
    
+0

它工作正常。使用相同的示例數據,我怎樣才能轉換成以下格式:''nvd3 options ='options'data ='data'api =「api」config =「{refreshDataOnly:true,deepWatchData:true}」>'。我使用相同的[http://bl.ocks.org/gencay/4629518]圖 – satheesh

+0

@satheesh提供jsFiddle。 –

+0

我在[https://gist.github.com/gencay/4629518#file-index-html]中使用相同的代碼。我需要在自定義指令中顯示此圖。 – satheesh