2016-04-21 69 views

回答

0

我发现这里的例子:Nvd3.js: Stacked/Grouped Multi-Bar Chart

nv.addGraph(function() { 
var chart = nv.models.multiBarChart() 
    .transitionDuration(350) 
    .reduceXTicks(true) //If 'false', every single x-axis tick label will be rendered. 
    .rotateLabels(0)  //Angle to rotate x-axis labels. 
    .showControls(true) //Allow user to switch between 'Grouped' and 'Stacked' mode. 
    .groupSpacing(0.1) //Distance between each group of bars. 
; 

chart.xAxis 
    .tickFormat(d3.format(',f')); 

chart.yAxis 
    .tickFormat(d3.format(',.1f')); 

d3.select('#chart1 svg') 
    .datum(exampleData()) 
    .call(chart); 

nv.utils.windowResize(chart.update); 

return chart; 
}); 

//Generate some nice data. 
function exampleData() { 
    return stream_layers(3,10+Math.random()*100,.1).map(function(data, i) { 
    return { 
     key: 'Stream #' + i, 
     values: data 
    }; 
    }); 
}