-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
95 lines (80 loc) · 2.54 KB
/
index.php
File metadata and controls
95 lines (80 loc) · 2.54 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/* Database connection settings */
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'db';
$mysqli = new mysqli($host,$user,$pass,$db) or die($mysqli->error);
$data1 = '';
$data2 = '';
//query to get data from the table
$sql = "SELECT * FROM `datasets` ";
$result = mysqli_query($mysqli, $sql);
//loop through the returned data
while ($row = mysqli_fetch_array($result)) {
$data1 = $data1 . '"'. $row['data1'].'",';
$data2 = $data2 . '"'. $row['data2'] .'",';
}
$data1 = trim($data1,",");
$data2 = trim($data2,",");
var_dump($data1);
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<title>Accelerometer data</title>
<style type="text/css">
body{
font-family: Arial;
margin: 80px 100px 10px 100px;
padding: 0;
color: white;
text-align: center;
background: #555652;
}
.container {
color: #E8E9EB;
background: #222;
border: #555652 1px solid;
padding: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>USE CHART.JS WITH MYSQL DATASETS</h1>
<canvas id="chart" style="width: 100%; height: 65vh; background: #222; border: 1px solid #555652; margin-top: 10px;"></canvas>
<script>
var ctx = document.getElementById("chart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'radar',
data: {
labels: [1,2,3,4,5,6,7,8,9],
datasets:
[{
label: 'Data 1',
data: [<?php echo $data1; ?>],
backgroundColor: 'transparent',
borderColor:'rgba(255,99,132)',
borderWidth: 3
},
{
label: 'Data 2',
data: [<?php echo $data2; ?>],
backgroundColor: 'transparent',
borderColor:'rgba(0,255,255)',
borderWidth: 3
}]
},
options: {
scales: {scales:{yAxes: [{beginAtZero: false}], xAxes: [{autoskip: true, maxTicketsLimit: 20}]}},
tooltips:{mode: 'index'},
legend:{display: true, position: 'top', labels: {fontColor: 'rgb(255,255,255)', fontSize: 16}}
}
});
</script>
</div>
</body>
</html>