I tried to display two charts, one with data provided by default when the controller is created. And one with data provided by a promise. The first chart displays the data, but the second chart is empty. I can see both charts. It seems that the chart is not updated even if the model is changed. I also tried to create a button that pushes data in the model but it's not working either.
<c3chart bindto-id="chart3" chart-data="vm.working.datapoints" chart-columns="vm.working.datacolumns">
</c3chart>
<c3chart bindto-id="chart4" chart-data="vm.notworking.datapoints" chart-columns="vm.notworking.datacolumns">
</c3chart>
angular
.module('app.sport')
.controller('SportController', SportController);
function SportController(logger, $q, $stateParams, DashboardsService) {
// vm is the same as $scope
var vm = this;
vm.getDashboard = getDashboard;
vm.sport = undefined;
vm.dashboard = undefined;
vm.working = {};
vm.working.datapoints = [{"x": 10, "top-1": 10, "top-2": 15},
{"x": 20, "top-1": 100, "top-2": 35},
{"x": 30, "top-1": 15, "top-2": 75},
{"x": 40, "top-1": 50, "top-2": 45}];
vm.working.datacolumns = [{"id": "top-1", "type": "line"},
{"id": "top-2", "type": "spline"}];
vm.notworking = {};
activate();
function activate() {
vm.sport = $stateParams.sport;
var promises = [getDashboard(vm.sport)];
return $q.all(promises).then(function (results) {
logger.info('Activated Sport View');
});
}
function getDashboard(sport) {
return DashboardsService.getSportDashboard(sport, true)
.then(function (dashboard) {
vm.notworking.datapoints = [{"x": 10, "top-1": 10, "top-2": 15},
{"x": 20, "top-1": 100, "top-2": 35},
{"x": 30, "top-1": 15, "top-2": 75},
{"x": 40, "top-1": 50, "top-2": 45}];
vm.notworking.datacolumns = [{"id": "top-1", "type": "line"},
{"id": "top-2", "type": "spline"}];
})
}
}