Angular nvd3折线图自动调整大小

ssb*_*sbb 17 javascript angularjs nvd3.js angularjs-nvd3-directives

我正在使用angular nvd3指令.

根据例子:https://github.com/angularjs-nvd3-directives/angularjs-nvd3-directives/blob/master/examples/lineChart.with.automatic.resize.html

<!--
width and height are removed from the directive for automatic resizing.
-->
Run Code Online (Sandbox Code Playgroud)

好吧,如果我更改图表的Div大小.它调整大小,但只有当我移动/打开/关闭'控制台视图'(FF上ctrl+ shift+ i)时.

我检查了angular-nvd3-directive,调整大小没有事件调用,所以我想这是一个d3/nvd3 comportement?

到目前为止我的问题:如何模拟这种事件以使图形调整大小?

Dyl*_*ade 8

您可以尝试触发另一个可以重新绘制图形的resize事件. window.dispatchEvent(new Event('resize'));

Chart.js也采用了类似的方法.当可见的控制台改变页面时,这很奇怪 - 仍然不完全理解它是如何工作的,但它会定期显示动态布局.

  • 控制台可见性更改页面的原因是,如果它们停靠,则切换开发人员工具会调整浏览器窗口的大小并调度resize事件.如果通过拖动浏览器窗口的边缘来更改其尺寸来调整大小,则同样如此. (4认同)