html - Nvd3 chart huge with oficial Css -


i having unexpected problems couple of nvd3 charts. coded them withouht using nvd3 css file (nv.d3.min.css). without ok when added suddendly second chart took lot of space (1500x1500). normal size 450x450 is

if in console of chrome , uncheck style atributes "width: 100%;" , "height: 100%;" works (actually one). other thing changes de css atributes "user agent stylesheet".

i can´t understand why because thought size explicitely coded while configuration of chart

html

<div id="charts"> <div id="piechart" ><svg></svg></div> <div id="chart"><svg></svg></div> </div> 

nvd3

    function setupgraph(data_graph) {         nv.addgraph(function() {             var piechart = nv.models.piechart();             piechart.margin({top: 30, right: 60, bottom: 20, left: 60});             var datum = data_graph[0].values;          piechart.tooltipcontent(function(key, y, e, graph) {                 var x = string(key);                   var y =  string(y);                    tooltip_str = '<center><b>'+x+'</b></center>' + y;                   return tooltip_str;                   });          piechart.showlabels(true);         piechart.donut(false);          piechart.showlegend(true);              piechart                 .x(function(d) { return d.label })                 .y(function(d) { return d.value });              piechart.width(450);             piechart.height(450);                  d3.select('#piechart svg')                 .datum(datum)                 .transition().duration(350)                 .attr('width',450)                 .attr('height',450)                 .call(piechart);          nv.utils.windowresize(chart.update);         return chart;             });      }      function setupgraph2(data_graph) {         nv.addgraph(function() {         var chart = nv.models.discretebarchart()           .x(function(d) { return d.label })    //specify data accessors.           .y(function(d) { return d.value })           //.valueformat(d3.format(',.2f'))           .staggerlabels(true)    //too many bars , not enough room? try staggering labels.           .tooltips(false)        //don't show tooltips           .showvalues(true)       //...instead, show bar value right on top of each bar.           .transitionduration(350)           ;              chart.width(450);             chart.height(450);           d3.select('#chart svg')                 .datum(data_graph)                 .attr('width',450)                 .attr('height', 450)                 .call(chart);            nv.utils.windowresize(chart.update);         return chart;            }); 

can see happening?

just override default width , height properties of nvd3.css stylesheet, creating rule in stylesheet, , ensuring loaded after nvd3 stylesheet.

the last rule (with same specificity) wins:

svg {      width : auto;     height : auto; } 

or create more specific rule act on svgs only, like:

#charts svg {      width : 450px;     height : 450px; } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -