2016-04-26 14 views
1

nvd3 multichart yaxisではゼロから始まり、最大値は入力データによって決めることができますか?nvd3 multichart yaxisがゼロから始まる

私はchart.yDomain1([0,100])を試しました。グラフは最大100でカットオフになります。私は動的であるために最大値が必要です。

答えて

0

だから、私は、y軸はので、私は、私はマルチチャートの例からソースコード
を始め、それが半年後
場合でも、Idは好意を試してみて、返すと思っ範囲を設定する方法を見つけ出す助けhttps://github.com/nvd3-community/nvd3/blob/gh-pages/examples/multiChart.html

あなたがしたいことは、データの最大値を計算してから、chart.yDomain1()関数内でそれを使用することです。

例フィドル - https://jsfiddle.net/q72tzyaL/1/

var data = [{ 
     "key": "key", 
     "type": "bar", 
     "values": [ 
      { x: 2012, y: 40 }, 
      { x: 2013, y: 36 } 
     ] 
    }, { 
     "key": "key", 
     "type": "bar", 
     "values": [ 
      { x: 2012, y: 40 }, 
      { x: 2013, y: 36 } 
     ] 
    }]; 

// each item is an object from the array with an array of values 
// get the values that we need from that array and then get the max of that 
function getMax(item) { 
    return d3.max(item.values.map(function(d){ return d.y; })); 
} 

// get the max. Pass in your data array and the function to get max 
var max = d3.max(data, getMax); 

nv.addGraph(function() { 
    var chart = nv.models.multiChart() 
        .margin({top: 30, right: 60, bottom: 50, left: 70}) 
        .yDomain1([0, max]); 

    d3.select('#chart1 svg') 
     .datum(data) 
     .transition().duration(500).call(chart); 

    return chart; 
}); 
関連する問題