MAD9022 Simple Pie Chart
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 - 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">
</head>
<body> <canvas id="c" width="300" height="300"></canvas> <script src="js/index.js"></script>
</body>
</html>
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;
}
Developer | Mobile Application Design-Development |
Username | mad-d |
Uploaded | August 10, 2022 |
Rating | 3 |
Size | 2,370 Kb |
Views | 34,408 |
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!
Name | Size |
MAD9022 Refactoring Practice | 2,315 Kb |
Mad9013 - column starter | 2,370 Kb |
MAD9013-F2015-Midterm | 4,641 Kb |
Cordova Cheatsheet | 2,534 Kb |
Mad9013 - DOM Manipulation sample | 3,113 Kb |
Contact Manager | 2,409 Kb |
HTML Canvas Samples | 5,370 Kb |
Mad9014 - objects and arrays | 2,606 Kb |
MAD9013 - Float Images with Content | 2,220 Kb |
Party Starter | 1,676 Kb |
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!
Name | Username | Size |
Scroll effect with text with help from Skrollr | Luxonglassing | 2,935 Kb |
Button fills | Zubfatal | 5,205 Kb |
Angular Sandbox | Alexgurrola | 1,616 Kb |
Fading gradient button | Insprd | 1,713 Kb |
A Pen by Mike Otis | Mikeotis | 3,185 Kb |
Foundation 5 Menu - Accessibility | Xporter | 1,999 Kb |
SVG email test v2.0 | M_J_Robbins | 2,090 Kb |
Heatmap Color Scales | Stevepepple | 2,331 Kb |
Sidebar Thing | Jonambas | 2,779 Kb |
React TODO | Enieste | 3,320 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!