MAD9022 Simple Pie Chart

2,370 Kb

How do I make an mad9022 simple pie chart?

HTML5 Canvas simple pie chart. What is a mad9022 simple pie chart? How do you make a mad9022 simple pie chart? This script and codes were developed by Mobile Application Design-Development on 10 August 2022, Wednesday.

MAD9022 Simple Pie Chart Previews

MAD9022 Simple Pie Chart - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>MAD9022 Simple Pie Chart</title> <link rel="stylesheet" href="css/style.css">
<body> <canvas id="c" width="300" height="300"></canvas> <script src="js/index.js"></script>

MAD9022 Simple Pie Chart - Script Codes CSS Codes

#c{ border:1px solid red;

MAD9022 Simple Pie Chart - Script Codes JS Codes

document.addEventListener("DOMContentLoaded", function(){ var values = [.20, .30, .15, .18, .17]; //NOTE THAT THESE ADD UP TO 1.0 var canvas = document.getElementById("c"); var context = canvas.getContext("2d"); var cx = canvas.width/2; var cy = canvas.height/2; var radius = 100; //start at zero degrees (or zero Radians) var currentAngle = 0; for(var i=0; i<values.length; i++){ var colour = setColour(values[i]); //DRAW THE ARCS //context.strokeStyle = "#0CF"; //context.lineWidth = 1; //uncomment the above if using stroke() too var endAngle = currentAngle + (values[i] * (Math.PI * 2)); //CALCULATE PERCENTAGE OF CIRCLE IN RADIANS context.moveTo(cx, cy); //move to middle of the circle //context.fillStyle = colour; context.beginPath(); context.fillStyle = colour; radius = 300 * values[i]; context.arc(cx, cy, radius, currentAngle, endAngle, false); context.lineTo(cx, cy); context.fill(); context.closePath(); //UPDATE THE CURRENT ANGLE TO BE READY FOR THE NEXT SEGMENT currentAngle = endAngle; }
function setColour(val){ //SET THE COLOURS var intColour = parseInt(val * 16777215); //PERCENTAGE OF FULL 24-bit console.log(intColour); var red = ((intColour >> 16) & 255); red = red.toString(16); //convert the decimal number to HEX if(red.length==1) red = "0" + red; var green = ((intColour >> 8) & 255); green = green.toString(16); if(green.length==1) green = "0" + green; var blue = (intColour & 255); blue = blue.toString(16); if(blue.length==1) blue = "0" + blue; console.log(red, green, blue); //var colour = "rgb(" + red +"," + green+"," + blue+")"; var colour = "#" + red + green + blue; //An alternative would be to use rgb(red, green, blue) return colour;
MAD9022 Simple Pie Chart - Script Codes
MAD9022 Simple Pie Chart - Script Codes
Home Page Home
Developer Mobile Application Design-Development
Username mad-d
Uploaded August 10, 2022
Rating 3
Size 2,370 Kb
Views 34,408
Do you need developer help for MAD9022 Simple Pie Chart?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Mobile Application Design-Development (mad-d) Script Codes
Create amazing captions with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!