2013-12-11 52 views
0

你好,我正在努力做一个散点图与nvd3.js库。现在的事情是我想要两个轴的宽度/高度相同。但即使代码中的css的高度和宽度都设置为相同的高度,y轴的高度也会更长。NVD3.js scatter

JS:

var chart = nv.models.scatterChart() 
          .width(300) 
          .height(300) 
          .showXAxis(true) 
          .showYAxis(true) 
          .forceX([-100,100]) 
          .forceY([-100,100]) 
          .tooltips(true) 
          .showLegend(false) 
          .tooltipContent(function(){ 
           return 'clock'; 
          }); 

CSS:

#main-chart { 
    width: 300px; 
    height: 300px; 
    margin: 0 auto; 
} 

HTML:

<div class="container" ng-controller="film_factor_controller"> 
    <svg bubble-chart id="main-chart"></svg> 

希望有人能帮助我

+0

可能重复[如何设置nvd3图表的高度和宽度](http://stackoverflow.com/questions/16474988/how-to-set-height-and-width-of-nvd3-chart) – shabeer90

回答

0

从源代码中可以发现,forceX和forceY被设置为使用D3的domain()API的图表。所以我猜这里的nvd3 API不会真的“强制”,因为实际长度将由d3计算,并且由输入范围决定。

也许你需要自己计算域,以便maxY和maxX正好位于轴的边缘。