I remember that something similar happened to me when working with Highcharts .
The root cause of the misalignment is probably the dynamic rendering time of the browser, which limits the canvas / svg container space.
To work around this problem, simply wrap up the creation of the timeout plot to display it in the next digest cycle:
App.directive('chart', function() { return { restrict: 'A', link: function(scope, elem, attrs) { var data = scope[attrs.ngModel]; setTimeout(function(){ $.plot(elem, data, {}); scope.$apply(); }, 0); } }; });
See the setTimeout fiddle here .
Alternatively, you can enter angular $timeout , so it already calls scope.$apply() for you:
App.directive('chart', ['$timeout', function($timeout) { return { restrict: 'A', link: function(scope, elem, attrs) { var data = scope[attrs.ngModel]; $timeout(function() { $.plot(elem, data, {}); }, 0); } }; }]);
Take a look at the work of $timeout here.
source share