Hello,
I have the following problem, I have a select
with an onchange method that I would like to update a div
. The reason for this is because I have a 3 graphics done in angular-chart.js and (supposedly) when values that the chart variable should change, it should update (supposedly), but it does not update.
As I am using this for IONIC I do not know if Ajax works, and I do not understand jQuery, if it is possible to use it for this, I will accept your questions.
My HTML:
<select ng-controller="chartController" ng-options="city.name for city in selectedState.cities"
ng-model="selectedCity" ng-change="updateGrafico()">
<option value="">Selecionar</option>
</select>
//div com um gráfico para exemplo
<div id="charts" class="item item-divider" ng-controller="chartController">
Indices de Excesso e Deficiência:
<div class="item item-text-warp" >
<canvas id="base" class="chart-bar" chart-data="dataDefExce"
chart-labels="labels" chart-colors="colors"
chart-dataset-override="datasetOverrideDuplo">
</canvas>
</div>
</div>
My controller:
.controller('chartController', function($http, $scope) {
$scope.colors = ['#000000', '#FF0000', '#00FFFF'];
$scope.labels = ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'];
$scope.selectedCity = {id:'1'};
var ret;
$scope.updateGrafico = function(){
var idCidade = $scope.selectedCity.id;
console.log(idCidade);
$http
.get(myrepository)
.success(function(response) {
$scope.cityOBJ = response;
popularGrafico();
});
}
function popularGrafico() {
this.ret = $scope.cityOBJ[0];
$scope.dataEvapo = [this.ret.info.etppri];
$scope.dataDefExce = [this.ret.info.bh.ex, this.ret.info.bh.def];
$scope.dataPrecip = [this.ret.info.bh.pr];
console.log(this.ret);
}
$scope.datasetOverrideDuplo = [{
label: "Bar chart",
borderWidth: 1,
type: 'bar'
}, {
label: "Line chart",
borderWidth: 3,
hoverBackgroundColor: "rgba(255,99,132,0.4)",
hoverBorderColor: "rgba(255,99,132,1)",
type: 'line'
}];
$scope.datasetOverrideGraficoUnico = [{
yAxisID: 'y-axis-1'
}, {
yAxisID: 'y-axis-2'
}];
$scope.options = {
scales: {
yAxes: [{
id: 'y-axis-1',
type: 'linear',
display: true,
position: 'left'
}]
}
};
})