-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.php
32 lines (28 loc) · 1.01 KB
/
product.php
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
<?php
include 'konek.php';
// Connect to the MySQL database
// Retrieve the data from the database
$query = "SELECT District, COUNT(*) as JumlahNode FROM node_addr GROUP BY District";
$result = mysqli_query($conn, $query);
// Format the data for Chart.js
$data = array();
while ($row = mysqli_fetch_assoc($result)) {
$data[] = array(
"label" => $row["District"],
"value" => $row["JumlahNode"],
"color" => "#" . substr(md5(rand()), 0, 6),
"border" => 5,
"skip" => false,
"borderWidth" => 1
);
}
// Create the Chart.js chart object
$chart_data = json_encode(
array("labels" => array_column($data, "label"),
"datasets" => array(
array("data" => array_column($data, "value"),
"borderRadius" => array_column($data, "border"),
"borderSkipped" => array_column($data, "skip"),
"borderWidth" => array_column($data, "borderWidth"),
"backgroundColor" => array_column($data, "color")))));
?>