饼图是将一个圆分割为多个扇形。
样例:http://www.zhaojz.com.cn/demo/draw8.html
复制代码 代码如下:
//饼图
//dot 圆点
//r 半径
//data 数据(一维数组)
function drawpie(dot, r, data){
if(data && data.length > 0){
var accumulationangleofslope = new number(0); //累计偏移角度
var total = new number(0);
var i = 0;
for(;i total += data[i];
}
for(i = 0;i var angle = new number(360*data[i]/total).tofixed(3); //将data[i]/total转换为角度
//画一个扇形
drawsector(dot, r, new number(angle), new number(accumulationangleofslope), true, number(parsefloat(data[i]/total)*100).tofixed(3)+'%');
accumulationangleofslope = accumulationangleofslope+parsefloat(angle); //累计偏移角度
}
}
}
