pablojim / highcharts-ng

AngularJS directive for Highcharts
MIT License
1.73k stars 463 forks source link

Angular ui-tab component and highchart reflow problem #627

Closed Kitzi16 closed 6 years ago

Kitzi16 commented 6 years ago

Hello,

I've just previously updated to Highchart 5 and now I was already able to solve a few problems that this have caused, but there's still one problem I can't get a solution for. My charts are not resized correctly when I'm switching tabs, they're usually displayed too large.

The tab component is the regular uib-tabs Angular component, we're using angular 1.5.* "highstock-release": "5.0.13" "highcharts-ng": "1.1.0"

In Highchart 4 we've solved this problem by using the func: function() and calling a timeout where the redraw is set if the tab is visible. I've had to find out that func: function call is not working like this in Highchart 5, so I've tried to use this code in the chart.events Listener. This was solving the problem I've had with resizing the browser, but not the tab-component problem. I guess the event isn't called, because when I'm resizing the browser, it works completely fine.

chart: {
            type: 'area',
                events: {
                load: function() {
                    var chart = this;
                    if(chart != null) { //Tried using it without, getting nullpointers all the time
                        $timeout(function () {
                            chart.reflow(); //reflow after timeout
                        }, 100);
                    }
                }
            }
        },

This was our previous used function working correctly in Highchart 4. I've also tried using the exact same code and it's not working that way either.

func: function(chart) {
                $timeout(function() {
                    if (angular.element(chart.container).parents('.tab-pane').is(':hidden')) {
                        angular.element(chart.container).parents('.tab-pane').addClass('hidden-element');
                        chart.reflow();
                        angular.element(chart.container).parents('.tab-pane').removeClass('hidden-element');
                    } else {
                        chart.reflow();
                    }
                },0);
            }

Is this a known issue somebody you could help me with? Would be glad to get some help, thank you

Kitzi16 commented 6 years ago

Okay this can be closed, I have fixed it by adapting my code slightly. It looks like there was a mistake in the previous code too, but somehow it did work.

Anyways, solution is the setting the tab-pane to a block element visability hidden for a short time, so the reflow does adjust to the size of the tab container.