最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular nvd3 Line Chart automatic resizing - Stack Overflow

programmeradmin12浏览0评论

I'm using angular nvd3 directives.

according to the exemple :.with.automatic.resize.html

<!--
width and height are removed from the directive for automatic resizing.
-->

Well, if I change The Div size of the graph. it resize but only when I move/open/close the 'console view' (ctrl + shift + i on FF).

I check on angular-nvd3-directive, There is no event call for the resize, so I suppose it's a d3/nvd3 comportement?

My question so far: How to simulate this kind of event for the graph to resize?

I'm using angular nvd3 directives.

according to the exemple :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.
-->

Well, if I change The Div size of the graph. it resize but only when I move/open/close the 'console view' (ctrl + shift + i on FF).

I check on angular-nvd3-directive, There is no event call for the resize, so I suppose it's a d3/nvd3 comportement?

My question so far: How to simulate this kind of event for the graph to resize?

Share Improve this question edited Apr 5, 2017 at 15:35 Cœur 38.7k26 gold badges202 silver badges277 bronze badges asked Jun 30, 2015 at 13:30 ssbbssbb 1,9312 gold badges22 silver badges45 bronze badges 1
  • Could you put the code you have into a fiddle or jsbin? – Dylan Valade Commented Jul 9, 2015 at 13:37
Add a comment  | 

3 Answers 3

Reset to default 8

You could try firing another resize event which could repaint the graph. window.dispatchEvent(new Event('resize'));

A similar approach worked for me with Chart.js. It's odd when the console being visible changes the page - still don't fully understand how that works but it shows up regularly with dynamic layouts.

I am not sure it will help you or not but I guess you can update the graph while your div resize it works in my case:-

For example:-

$('#my_div').bind('resize', function(){

            for (var i = 0; i < nv.graphs.length; i++) {
                nv.graphs[i].update();
            }

});

You can add a jquery resize event handler, if you are not using jquery then you can attach event handler using angular only.

Using jQuery

$(document).on('resize', function() {

  for (var i = 0; i < nv.graphs.length; i++) {
    nv.graphs[i].update();
  }

});

Using Angular Only

Here is an example shows how to attach event do document using angular.

发布评论

评论列表(0)

  1. 暂无评论