Home  >  Article  >  Web Front-end  >  Use js to draw pie charts_javascript skills

Use js to draw pie charts_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:20:461576browse

Use js to draw pie chart

A pie chart is a circle divided into multiple sectors.

Sample: http://www.zhaojz.com.cn/demo/draw8.html

Copy code The code is as follows:

//Pie chart
//dot dot
//r radius
//data data (one-dimensional array)
function drawPie(dot, r, data){
If(data && data.length > 0){
          var accumulationAngleOfSlope = new Number(0); //Accumulated offset angle
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); //Convert data[i]/total to angle
                //Draw a fan shape
               drawSector(dot, r, new Number(angle), new Number(accumulationAngleOfSlope), true, Number(parseFloat(data[i]/total)*100).toFixed(3) '%');
               accumulationAngleOfSlope = accumulationAngleOfSlope parseFloat(angle); // Accumulated offset angle
}
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn