2013-12-19 73 views
4

更改X標註軸我與格式數據的簡單線圖:NVD3 - 上線圖

[ 
    { 
     label: "lebel1", 
     x: 0, 
     y: 128 
    }, 
    { 
     label: "lebel1", 
     x: 1, 
     y: 128 
    }, 
    .... 
    { 
     label: "lebel2", 
     x: 25, 
     y: 128 
    }, 
    .... 
    { 
     label: "lebel8", 
     x: 285, 
     y: 128 
    }, 
    .... 

}

,我通過這個進我nvd3對象:

nv.addGraph(function() 
{ 
    var chart = nv.models.lineChart(); 

    chart.xAxis 
     .axisLabel("My X-Axis") 
     .ticks(36) 
     .tickFormat(function(d) { return d; }); 

    chart.yAxis 
     .axisLabel('Voltage (v)') 
     .tickFormat(d3.format('.02f')); 

    d3.select('div svg') 
     .datum(myData) 
     .transition().duration(500) 
     .call(chart); 

    nv.utils.windowResize(function() { d3.select(gridSvgId).call(chart) }); 

    return chart; 
}); 

我怎麼能有我的x軸的刻度顯示: * 8個標籤:LABEL1 -

的Label8

而不是把網格分解成多行?

回答

3

嘗試這樣的事情

chart.xAxis.tickValues(['Label 1','Label 2','Label 3','Label 4','Label 5','Label 6','Label 7','Label 8']); 

,或者如果你想從數據集中得到它,你可以嘗試這樣的事情,

chart.xAxis.tickValues(function(d) { 
    // do all you stuff and return an array 
    var dataset = ['Build Array from data']; 

    return dataset; 
};) 

希望它可以幫助