I am currently working on generating a pie chart using highcharts to visualize the distribution of each value assigned to a specific column (TYP_CODE) relative to the total number of entries.
synthese.php :
<?php
session_start();
if(!isset($_SESSION['nom']))
{
header("Location:Login.php");
}
try {
$connexion = new PDO('mysql:host=localhost;dbname=gsbv1;charset=utf8', 'root', '');
// echo 'Successfully connected to the database ';
} catch (Exception $e) {
die('Error : ' . $e->getMessage());
}
$json_data= include ('fonctionbdd.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style_rapport.css">
<script src="https://kit.fontawesome.com/edec10413c.js" crossorigin="anonymous"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital@1&display=swap" rel="stylesheet">
<title>Reports</title>
</head>
...
fonctionbdd.php:
<?php
try {
$connexion = new PDO('mysql:host=localhost;dbname=gsbv1;charset=utf8', 'root', '');
// echo 'Successfully connected to the database ';
} catch (Exception $e) {
die('Error : ' . $e->getMessage());
}
$sql="SELECT COUNT(DISTINCT TYP_CODE) as TYP_CODE FROM praticien";
$reponse = $connexion->query($sql);
if ($reponse->rowCount() > 0) {
while($row = $reponse->fetch(PDO::FETCH_ASSOC)) {
$arr=array(
'name'=>$row['TYP_CODE'],
'data'=>array_map('intval', explode(',', $row['TYP_CODE']))
);
$series_array[]= $arr;
}
return json_encode ($series_array) ;
}
?>
And the .sql file:
-- phpMyAdmin SQL Dump
-- version 5.0.2
...
...