carlcraig / tc-angular-chartjs

AngularJS directives for Chart.js
http://carlcraig.github.io/tc-angular-chartjs/
Other
233 stars 83 forks source link

Dynamically change chart type #89

Open alamsha opened 7 years ago

alamsha commented 7 years ago
    <canvas tc-chartjs chart-type="type" chart-data="chartData" chart-options="options" chart="variable">
    </canvas>

$scope.type = 'bar';

In the above code, chart type is not changing from the controller scope. But this works perfectly in angular-chartjs. How can i change the chart type dynamically by clicking a button?. Thanks.

abarinoff commented 7 years ago

I had the same issue and solved it by wrapping type into {{}}. According to source code chart-type attribute handling differs from the one for chart-data and chart-options attributes. Directive scope is defined as follows:

scope: { data: '=chartData', options: '=chartOptions', type: '@chartType', ... }

Working code for me:

<canvas tc-chartjs chart-type="{{$ctrl.chartType}}" chart-data="$ctrl.chartData" chart-options="$ctrl.chartOptions"></canvas>