Accepted answer

I think I found solutions to both of my problems:

  1. Wrong size when chart finishes loading:

The problem does not come from Highcharts, but from the timing when the chart is created. I directly called .highcharts() from the link() function of my Angular directive. The JS looking essentially like this:

app.directive('dynamicView', function() {
  return {
    link: function(scope, element, attrs){

As my element also has a ng-if directive depending on whether the tab is selected or not, I imagine that when that condition turns true, angular calls the link() function before the dimension of the element is determined (I guess the HTML has to be ready in order to determine the size of the elements). So I think the problem was that I was calling .highcharts() before the document was ready. For some reason that I still don't understand, the size of the element is correct the first time ng-if turns true, but incorrect the next times.

Anyway, a solution (still not very elegant - but better than calling reflow()) is to delay the call to .highcharts() itself, to make sure that the HTML is ready when creating the charts:

link: function(scope, element, attrs){
  setTimeout(function () {
  }, 0);

Thank you @Pavel Fus for your comments on the behaviour of .highcharts() and setTimeout().

  1. Chart not resizing when toggling a class

For this problem I took advantage of Angular's eventing system.

In my controller controlling the full-screen button:

$scope.toggleFullScreen = function(e){

This event is passed down the hierarchy, ending-up to my directives containing the charts. All I have to do, when creating my charts is to listen to this event, and trigger a reflow() accordingly:

scope.$on('fullscreen', function(){
  setTimeout(function () { 
  }, 0);

Note that --again-- the trick only works if I delay the reflow with setTimeout(). Not sure why.

I hope this helps! Spent quite a bit of time on this...


So, in fact you have two questions:

1) Incorrect size at second click. This is most probably caused by wrong width and height for a hidden (display: none) container. In that case, browsers report incorrect width/height (like 0px). The same question here and here.

2) Setting class for a container wouldn't fire resize (or rather reflow) event for a chart. That mean you need to call chart.reflow() on your own. I suggest to do that in the same place as you change your class.

Related Query

More Query from same tag