angular-chart.js icon indicating copy to clipboard operation
angular-chart.js copied to clipboard

Chart is not working if I use ng-show

Open hajoxx opened this issue 11 years ago • 9 comments

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.

hajoxx avatar Feb 20 '15 15:02 hajoxx

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.

jtblin avatar Feb 20 '15 15:02 jtblin

Thanks for suggestion, the chart is still not working because I have to use ng-show to show a simple loading bar.

hajoxx avatar Feb 20 '15 16:02 hajoxx

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.

csheets avatar Feb 20 '15 18:02 csheets

Thanks! I'm looking to it now.

hajoxx avatar Feb 20 '15 18:02 hajoxx

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 avatar Feb 22 '15 05:02 jtblin

@jtblin, even so that workaround worked it is not an angular way at all...

IgorUzhviev avatar Mar 04 '15 22:03 IgorUzhviev

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 ?

gstrit avatar Jun 18 '15 18:06 gstrit

You can use ng-if instead ng-show/ng-hide. Works for me.

tortik avatar Jul 06 '15 10:07 tortik

I had the same problem, but as @tortik said using ng-if will force a redraw of the container which also solves the issue.

LucasLazaro avatar Aug 04 '15 07:08 LucasLazaro