真机 request 之后添加数据到 饼图 不显示
setPie: function (val) { var array, colors, context, i, j, k, l, len, n, o, point, radius, ref, ref1, start, total; context = wx.createCanvasContext( 'pieCanvas' , this ); array = val; array = [0, 30, 20, 30, 20]; colors = [ "#8cd2f4" , "#c2cd23" , "#ffe512" , "#f78f1e" , "#f05133" ]; point = { x: 150, y: 150 }; radius = 140; total = 0; console.log( "array" , val); for (k = 0, len = array.length; k < len; k++) { n = array[k]; total += n; } for (i = l = 0, ref = array.length; (0 <= ref ? l < ref : l > ref); i = 0 <= ref ? ++l : --l) { context.beginPath(); start = 0; if (i > 0) { for (j = o = 0, ref1 = i; (0 <= ref1 ? o < ref1 : o > ref1); j = 0 <= ref1 ? ++o : --o) { start += array[j] / total * 2 * Math.PI; } } console.log( "start:" , start, i, array[i]); context.arc(point.x, point.y, radius, start, array[i] / total * 2 * Math.PI, false ); context.lineTo(point.x, point.y); context.setFillStyle(colors[i]); context.fill(); context.closePath(); } return context.draw(); }, |
如果 val 是 request 回来的的数组真机上就不显示饼图, 但是如果是自定义的数据(和 request 返回回来的一模一样) 就显示. 模拟器没问题, 真机有问题.