score:7
I think I found solutions to both of my problems:
- 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){
$(element).highcharts({...});
},
};
});
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 () {
$(element).highcharts({...});
}, 0);
}
Thank you @Pavel Fus for your comments on the behaviour of .highcharts()
and setTimeout()
.
- 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){
$scope.$broadcast('fullscreen');
}
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 () {
$(element).highcharts().reflow();
}, 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...
score:1
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.
Source: stackoverflow.com
Related Query
- Highcharts dynamic (re-)sizing in AngularJS tabs
- AngularJS for Highcharts with dynamic ajax data
- Highcharts in JQuery Tabs - Resizing hidden tab code stops resizing visible tab
- HighCharts in AngularJS with dynamic data
- Dynamic creation og Highcharts in Angularjs
- Responsive Highcharts not sizing correctly until window resize
- Highcharts - how to have a chart with dynamic height?
- jQuery UI Tabs and Highcharts display/rendering issue
- Highcharts does not resize charts inside tabs
- HighCharts - How to create dynamic chart that exports EVERYTHING
- Highcharts - set maximum range for yAxis but keep axis dynamic within that range
- how to set dynamic data in highcharts
- highcharts jquery dynamic change chart type column to bar
- Dynamic update of multiple series in highcharts
- Highcharts in AngularJs without jQuery?
- highcharts graphs in bootstrap tabs are not displaying properly
- How to structure Angular with Highcharts and lots of dynamic data
- Add dynamic data to line chart from mysql database with highcharts
- How to handle Highcharts events from an AngularJS directive?
- How to display highcharts in ng-repeat angularjs
- Adding multiple dynamic lines to highcharts
- Using PhantomJS to create HighCharts grahps server side for use in PDF creation (PHP) - results in exit code 11 from PHPs exec();
- Dynamic data in Highcharts
- highcharts not loading in tabs
- Highcharts - Global configuration with common code and unique data & Headings
- Hidden Highcharts not sizing correctly until window resize
- Highcharts Dynamic candlestick
- Using Highcharts display donut hightchart having dynamic data
- Golang Highcharts dynamic data
- HighCharts : dynamic data with drill down
More Query from same tag
- Adding information to xAxis - r shiny
- Highcharts full circle gauge as in Knob js
- Display HighStock y-axis and its labels on the right of the series
- Change graph color above and below plot-line in Column chart in Highcharts
- How can I prevent Highcharts from displaying decimal intervals in between x-axis ticks?
- Memory leak in setInterval() method
- Highchart - Show histogram results using waterfall style rendering
- Want Stacked column highchart to represent data in two column
- Highcharts: Rotate VU dials
- highcharts world map not rendering
- Highcharts redraw previous line still exist
- How to get current drilldown's id in Highcharts
- How to have shadow enabled in hover and select of highmap?
- In Highstock, overlapping flags when existing multiple series
- HighChart Stacked column bar
- Highchart : xaxis Adding extra Dates randomly
- How to control Two chart of highstock with scroll bar
- Unresponsive touch in android webview
- Get the JSON encode result from the Controller to View
- How do I remove the pale line between events in a Highcharts columnrange chart?
- How to point the range(dataClasses) for 2nd index in data using highcharts?
- Manually drilldown highcharts
- Solid Gauge: Prevent y-axis label from overlapping gauge
- Combine PieChart with Map
- Group records in Rails for a chart?
- HighCharts Organization Nodes Overlapping
- Highcharts doesnot reload or re-render chart on value change
- Highcharts same legend color as of the Pie chart slice color?
- Highcharter format number in tooltip
- Highcharts chart with 'datetime' xAxis - use categories on drilldown