3
I have a problem when creating a chart with Chart.js and then do to generate another chart from the menu that is on the same page. It creates the graph, but when I move the cursor across the graph it switches to the previous graph.
Update
After a search in the chartJS documentation I found a supposed method that clears the chart information with the .removeData()
. I applied this method to the controller, but unfortunately it continues to present the previous graphic in background when I hover the mouse over the graph. I also performed a console.log
in the array containing the information and this information is updated with the latest information request envoy.
Controller code
$scope.getChart = function (report) {
$scope.modalLabels = [];
$scope.data = {values: ([])}; //Array that contains the data recieved from the server
if($('#chartBar')!=null){
$('#chartBar').removeData();
}
/*Funçao para que obtém as informações por parte do servidor*/
//Se receber informação
var avgCapacity = [];
for (var i = 0, length = data.length; i < length; i++) {
avgCapacity.push(data[i].Volume);
$scope.modalLabels.push(data[i].Day + "/" + data[i].Month);
}
$scope.data.values = ([avgCapacity]);
First graph Second graph Html that generates Graphics:
<div ng-hide="data==0">
<h4 id="chartTitle"><b>{{Title}}</b></h4>
<canvas id="bar" class="chart chart-bar" chart-data="data" chart-options="options"
chart-labels="modalLabels" chart-legend="true" chart-series="series">
It has the angular Hart js, in it has facilitators to create angular graphics I suggest take a look at it and try to do what you need. https://jtblin.github.io/angular-chart.js/#reactive
– joao paulo santos almeida