您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

使用js画图之饼图_javascript技巧

2024/11/6 17:40:30发布52次查看
使用js画图之饼图
饼图是将一个圆分割为多个扇形。
样例: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); //累计偏移角度
        }
    }
}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product