2016-04-26 5 views
1

Ist es möglich in nvd3 multichart yaxis von Null ausgehend zu beginnen und max von den Eingangsdaten bestimmt werden?nvd3 multichart yaxis start von null

Ich versuchte chart.yDomain1 ([0,100]); aber das Diagramm wird bei maximal 100 abgeschnitten. Ich brauche das Maximum, um dynamisch zu sein.

Antwort

0

So half man mir herauszufinden, wie die y-Achse setzen reicht also dachte ich, Id versuchen und revanchieren, auch wenn es sechs Monate später ist
ich mit dem Quellcode aus dem Multi-Chart Beispiel
gestartet https://github.com/nvd3-community/nvd3/blob/gh-pages/examples/multiChart.html

Was Sie tun möchten, ist das Maximum Ihrer Daten zu berechnen und dann innerhalb der chart.yDomain1() Funktion zu verwenden.

Beispiel Geige - 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; 
}); 
Verwandte Themen