nvd3.js - how to set height and width of nvd3 chart -
i'm trying set width , height of nvd3 multi bar chart programmatically using
chart.width(600); chart.height(400); see example here:
as can see messes chart. know can css with:
#chart svg { width: 600px; height: 400px; } but thought possible using width() , height() functions on chart. doing wrong here or mis-using 2 functions?
yes possible, have specified width & height of chart, have use d3.select , set width & height attribute.
changes code below , there version of code here
function visualizedata(data) { nv.addgraph(function() { var width = 600, height = 400; chart = nv.models.multibarchart().x(function(d) { return d.x; }).y(function(d) { return d.y; }).color(['#aec7e8', '#7b94b5', '#486192']).stacked(true) //.margin({top:150,right:150,bottom:150,left:150}) .width(width).height(height); chart.multibar.hideable(false); chart.xaxis.showmaxmin(true).tickformat(d3.format(',f')); chart.yaxis.tickformat(d3.format(',.1f')); d3.select('#chart svg').datum(data).transition().duration(500).call(chart).style({ 'width': width, 'height': height }); nv.utils.windowresize(chart.update); return chart; }); }
Comments
Post a Comment