Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 背景ChartJS中的多个图表_Javascript_Html_Angularjs_Chart.js - Fatal编程技术网

Javascript 背景ChartJS中的多个图表

Javascript 背景ChartJS中的多个图表,javascript,html,angularjs,chart.js,Javascript,Html,Angularjs,Chart.js,当我使用chart.js生成一个图表时,我遇到了一个问题,但是当我从同一页面的菜单生成另一个图表时,它会生成图表,但是当我将移动移动移动到图表上时,它会更改为上一个 更新 在chart.js文档中进行了一些研究后,发现了一种清除图表数据的方法,我在获取新数据之前应用于控制器,不幸的是,当鼠标悬停在图表上时,我在后台继续获取以前的图表我制作了一个包含值的数组的控制台日志,并使用最新请求的数据进行更新 来自控制器的代码 $scope.getChart = function (report) {

当我使用chart.js生成一个图表时,我遇到了一个问题,但是当我从同一页面的菜单生成另一个图表时,它会生成图表,但是当我将移动移动移动到图表上时,它会更改为上一个

更新

在chart.js文档中进行了一些研究后,发现了一种清除图表数据的方法,我在获取新数据之前应用于控制器,不幸的是,当鼠标悬停在图表上时,我在后台继续获取以前的图表我制作了一个包含值的数组的控制台日志,并使用最新请求的数据进行更新

来自控制器的代码

 $scope.getChart = function (report) {
 $scope.modalLabels = [];
 $scope.data = {values: ([])}; //Array that contains the data recieved from the server
if($('#chartBar')!=null){
        $('#chartBar').removeData();
    }
/*Function to request data to server*/
//If data recieved
 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]);
$scope.getChart=函数(报告){
$scope.modalLabels=[];
$scope.data={values:([])};//包含从服务器接收的数据的数组
如果($('#chartBar')!=null){
$(“#图表栏”).removeData();
}
/*函数向服务器请求数据*/
//如果收到数据
var avgCapacity=[];
对于(变量i=0,长度=data.length;i

这就是背后的html:

<div ng-hide="data==0">
    <h4 id="chartTitle"><b>{{Title}}</b></h4>
<canvas id="ChartBar" class="chart chart-bar" chart-data="data" chart-options="options"
        chart-labels="modalLabels" chart-legend="true" chart-series="series">
</canvas>
</div>

{{Title}}

在生成新图表之前,需要通过调用
.destroy()
销毁以前的图表实例。

在生成新图表之前,需要通过调用
.destroy()
销毁以前的图表实例