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

Use js to draw pie charts_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 16:20:46
Original
1653 people have browsed it

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
}
}
}
Related labels:
Statement of this Website
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
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template