1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| <?php
require_once("../lib/phpchartdir.php");
$connexion = new PDO("mysql:host='localhost';dbname=tadb", 'utilisateur', 'mot_de_passe'); // connexion à la BDD
$resultats=$connexion->query("SELECT id_produit,COUNT(id_produit) AS nbr_produit,(SELECT COUNT(id_produit) FROM vente) AS produit_total,(100/(SELECT COUNT(id_produit) FROM vente))*COUNT(id_produit) AS pourcentage
FROM vente
GROUP BY id_produit");
$resultats->setFetchMode(PDO::FETCH_OBJ); // on dit qu'on veut que le résultat soit récupérable sous forme d'objet
while( $ligne = $resultats->fetch() ) // on récupère la liste des membres
{
# The data for the pie chart
$data[] = $ligne->pourcentage;
# The labels for the pie chart
$labels[] = $ligne->id_produit;
}
# Determine the starting angle and direction based on input parameter
$angle = 0;
$clockwise = true;
# Create a PieChart object of size 280 x 240 pixels
$c = new PieChart(280, 240);
# Set the center of the pie at (140, 130) and the radius to 80 pixels
$c->setPieSize(140, 130, 80);
# Add a title to the pie to show the start angle and direction
if ($clockwise) {
$c->addTitle("Start Angle = $angle degrees\nDirection = Clockwise");
} else {
$c->addTitle("Start Angle = $angle degrees\nDirection = AntiClockwise");
}
# Set the pie start angle and direction
$c->setStartAngle($angle, $clockwise);
# Draw the pie in 3D
$c->set3D();
# Set the pie data and the pie labels
$c->setData($data, $labels);
# Explode the 1st sector (index = 0)
$c->setExplode(0);
# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?> |
Partager