使用js画图之饼图

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

使用js画图之饼图

  2020-05-13 我要评论

使用js画图之饼图

饼图是将一个圆分割为多个扇形。

样例:http://www.zhaojz.com.cnhttps://img.qb5200.com/download-x/demohttps://img.qb5200.com/download-x/draw8.html

复制代码 代码如下:

//饼图
/https://img.qb5200.com/download-x/dot 圆点
//r 半径
/https://img.qb5200.com/download-x/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<data.length;i++){ //计算data的合计
            total += data[i];
        }
        for(i = 0;i<data.length;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); //累计偏移角度
        }
    }
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们