Graphics overlay

3

I have a problem when I create a chart with chart.js and then I create another chart from the menu that is on the same page. It creates the graph, but when I move the cursor over the graph it changes to the previous graph.

Update

After a search in the chartJS documentation I found a supposed method that cleans the graph information with .removeData() . I applied this method to the controller, but unfortunately it still displays the previous graph in the background when I move the mouse over the graph. I also made a console.log in the array that contains the information and this information is updated with the last request information sent.

Driver 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 chart Secondchart Htmlthatgeneratesthegraphics:

<divng-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">

    
asked by anonymous 20.11.2015 / 18:20

1 answer

2

I had the same problem.

The solution was that when I changed the data I would remove the canvas from the DOM and insert a new canvas with the new values.

There I created a directive that encapsulated angular-chartjs directives and added two methods to the last object to it, create() and clear() .

Ex:

<my-charts chart-model="vm.chart"></my-charts>

This directive was intended to create and compile all the html by adding the values of the object vm.chart and giving it the create() and clear() .

When I needed to update the chart I made a clear() , updated the data and gave a create() .

I did this in my old work and unfortunately I no longer have access to the code.

    
28.10.2016 / 22:51