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