Is it possible to dynamically create a chart while still have a data binding to the scope?
I have the following code
<!DOCTYPE html>
<head>
<script src='Chart.js'></script>
<script src='angular.js'></script>
<script src='angular-chart.js'></script>
</head>
<body ng-app="app" ng-controller="BarCtrl">
<h1>Chart Test</h1>
<canvas id="myChart"> chart-series="series" </canvas>
<script type="text/javascript">
angular.module("app", ["chart.js"])
.controller("BarCtrl", function($scope, $timeout) {
$scope.labels = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
$scope.data = [65, 59, 80, 81, 56, 55, 40];
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: $scope.labels, //should be a reference
datasets: [{
data: $scope.data //should be a reference
}]
}
});
$timeout(function() {
console.log("Time out now");
$scope.data = [28, 48, 40, 19, 86, 27, 90];
}, 3000);
});
</script>
</body>
</html>
This obviously does not update the chart after the timeout. How would I have to create this chart instead when the template variant
<canvas class="chart chart-line" chart-data="data" chart-labels="labels"
chart-series="series" chart-click="onClick"></canvas>
is not an option because configuration changes dynamically?