Browse Source

pie fonction

master
quegzacov 2 years ago
parent
commit
6939a18257
  1. 21
      index.php
  2. 31
      script.js

21
index.php

@ -1,7 +1,22 @@
<?php <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Roulette à eau</title>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<code>
<?php
$bdd = new SQlite3('bdd.db'); $bdd = new SQlite3('bdd.db');
$query = $bdd -> query('SELECT * FROM Info'); $query = $bdd -> query('SELECT * FROM Info');
$res = $query -> fetchall(); $res = $query -> fetchArray();
var_dump($res); var_dump($res);
?> ?>
</code>
</body>
</html>

31
script.js

@ -1,2 +1,29 @@
console.log('hello') function pie(ctx, w, h, datalist)
const database = require('bdd.db') {
var radius = h / 2 - 5;
var centerx = w / 2;
var centery = h / 2;
var total = 0;
for(x=0; x < datalist.length; x++) { total += datalist[x]; };
var lastend=0;
var offset = Math.PI / 2;
for(x=0; x < datalist.length; x++)
{
var thispart = datalist[x];
ctx.beginPath();
ctx.fillStyle = colist[x];
ctx.moveTo(centerx,centery);
var arcsector = Math.PI * (2 * thispart / total);
ctx.arc(centerx, centery, radius, lastend - offset, lastend + arcsector - offset, false);
ctx.lineTo(centerx, centery);
ctx.fill();
ctx.closePath();
lastend += arcsector;
}
}
var datalist= new Array(35, 25, 20, 12, 7, 1);
var colist = new Array('blue', 'red', 'green', 'orange', 'gray', 'yellow');
var canvas = document.getElementById("canvas3");
var ctx = canvas.getContext('2d');
pie(ctx, canvas.width, canvas.height, datalist);
Loading…
Cancel
Save