-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
68 lines (63 loc) · 2.68 KB
/
index.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html lang="en">
<head>
<title>Pie Charts</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Link google chart API -->
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<?php
$connect = mysqli_connect("localhost", "root", "", "blog");
$SELECT = "SELECT * FROM chart";
$tugas = $_POST['tugas'];
$persentase = $_POST['persentase'];
$INSERT = "INSERT INTO chart (tugas, persentase) VALUES ('$tugas', '$persentase')";
$result = mysqli_query($connect, $SELECT);
if (!$connect) {
echo "connection failed" . mysqli_connect_error();
}
if (mysqli_query($connect, $INSERT)){
echo "nothing wrong until here";
} else {
echo "Error" . $INSERT . "<br>" . $mysqli_error($connect);
}
?>
<script type="text/javascript">
google.charts.load("current", {packages: ["corechart"]});
// Akan dihandle pada fungsi drawchart
google.charts.setOnLoadCallback(drawchart);
function drawchart() {
var chart = new google.visualization.PieChart(document.getElementById('daily'));
var data = google.visualization.arrayToDataTable([
['Daily Activities', 'Percentage'],
<?php
while($row = mysqli_fetch_array($result))
{
echo "['".$row["tugas"]."'," .$row["persentase"]."],";
}
?>
]);
var options = {
title: 'Daily Activities',
pieHole: 0.4, // Lubang pada pie Chart, tapi pieHole tidak akan muncul jika is3D = true
is3D: true // Ganti dengan false jika tidak ingin berbentuk 3D
};
chart.draw(data, options)
}
</script>
</head>
<body>
<div class="navbar"><span>Daily Activities</span></div>
<div class="container">
<form action="index.php" method="POST">
<label for="tugas">Tugas</label>
<input type="text" name="tugas">
<label for="persentase">Persentase</label>
<input type="text" name="persentase">
<button type="submit">Submit</button>
</form><br>
<div id="daily" style="width: 900px; height: 500px;"></div>
</div>
</body>
</html>