This commit is contained in:
girault
2022-05-17 12:35:25 +02:00
parent 8e1ed459d1
commit aa1b224c56
6 changed files with 275 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
let data=[
{"label":"C","value":50},
{"label":"C++","value":100},
{"label":"Java","value":20},
{"label":"PHP","value":60}
];

View File

@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<style>
canvas {background-color: red;}
</style>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<canvas></canvas>
</body>
<script src="./data.json"></script>
<script src="./main.js"></script>
</html>

55
WIM4.1/tp/tp4/ex1/main.js Normal file
View File

@@ -0,0 +1,55 @@
let color = ["#F00", "#0F0", "#00F", "#FF0", "#F0F", "#0FF"];
let height= 150
let witdh = 70;
let rayon = 50;
let valueMax = 0;
function name(argument) {
return 1;
}
data.forEach(el => valueMax += el.value);
window.onload = (()=> {
let ctx = document
.querySelector("canvas")
.getContext("2d");
let precedent_value = 0;
ctx.moveTo(witdh, height);
for (var i = 0; i<1; i++ ) {
ctx.fillStyle = color[i];
ctx.save();
ctx.beginPath();
ctx.lineTo(0, rayon);
ctx.arc(0, 0, rayon, 0, (Math.PI*2) *(data[i].value/valueMax), false);
ctx.restore();
ctx.rotate((Math.PI*2) *(data[i].value/valueMax));
ctx.lineTo(0, rayon);
ctx.fill();
ctx.stroke();
ctx.closePath();
ctx.restore();
}
})