之前要把canvas先清除掉,不然刷新数据,还会有前面的图表
function clearCanvas(){$('#donutChart').remove();$('#chartdiv').append('<canvas id="donutChart" style="min-height: 500px; height: 500px; max-height: 500px; max-width: 70%;"> </canvas>');container=document.getElementById("donutChart");context=container.getContext("2d");}
function ShowDishGroupPie(PieData){// [{"totalcount":0,"title":"菜品总条数","id":1,"per":0}]// alert(PieData.dbCount);// alert(JSON.stringify(PieData.dbData));// var length = Object.keys(PieData.dbData).length;var labels =[];var data = [];PieData.dbData.forEach(function(val, index) {if(val.title != '菜品总条数' && val.title != '平均用时(分钟)' && val.title != '传菜条数')labels.push( val.title);});PieData.dbData.forEach(function(val, index) {if(val.title != '菜品总条数' && val.title != '平均用时(分钟)' && val.title != '传菜条数')data.push( val.totalcount);});// for(i=0;i<PieData.dbCount - 1;i++)// {// alert(PieData.dbData)// }var ctx = document.getElementById("donutChart").getContext("2d");var data = {labels:labels,datasets: [{data: data,backgroundColor: ["#FF6384","#36A2EB","#FFCE56","#00FF00","#D2691E","#00FFFF","#FF00FF"],hoverBackgroundColor: ["#FF6384","#36A2EB","#FFCE56","#00FF00","#D2691E","#00FFFF","#FF00FF"]}]};pieOptions = {};var myPieChart = new Chart(ctx,{type: 'pie',data: data,options: pieOptions});}</script>