Chart is not working if I use ng-show
I added loaded variable to see a loading bar.
$scope.loaded = false
//things to load.... //chart options etc.
$scope.loaded = true
Html:
<div ng-show="loaded">
<canvas id="line" class="chart chart-line" data="chartData" labels="chartLabels" legend="true" series="chartSeries"
options="chartOptions"></canvas>
</div>
Whenloaded true, chart is not working.
Angular digest cycle is not synchronous and the chart will not be created right after setting the data. If you want to know when the chart is created, I suggest you listen to the "create" event using
$scope.$on('create', function () {
$scope.loaded = true;
});
On 20/02/2015 4:36 PM, "Rexota" [email protected] wrote:
I added loaded variable to see a loading bar.
$scope.loaded = false //things to load.... //chart options etc. $scope.loaded = true
Html:
Whenloaded true, chart is not working.
— Reply to this email directly or view it on GitHub https://github.com/jtblin/angular-chart.js/issues/67.
Thanks for suggestion, the chart is still not working because I have to use ng-show to show a simple loading bar.
If I am remembering correctly, I was seeing this at one point as well and it seemed to be that when ng-show was false then the canvas had no "size" or display:none (or something similar) and then the chart was never rendered which seems to be a common issue with ChartJS and so for me it seemed like this was a ChartJS issue: see https://github.com/nnnick/Chart.js/issues/512 for more info.
Thanks! I'm looking to it now.
Ok, this is the same issue as #29. Closing as duplicate.
The link posted by @csheets seems to have a workaround for the issue.
@jtblin, even so that workaround worked it is not an angular way at all...
IgorUzhviev is right. This is not the good way but I have no solution. I'm trying to use angularjs-chart with gridster but if have the same issue... Someone has a good solution ?
You can use ng-if instead ng-show/ng-hide. Works for me.
I had the same problem, but as @tortik said using ng-if will force a redraw of the container which also solves the issue.