I'm trying to plot graph on real time data on my website according to there patient_id in select tag.
In phpmyadmin database i have four column (temp,rate,date,patient_id
)
in followdata_temp
i getting data of temp as per time.
in main page i'm gettin select option as well as graph below it but I'm not able to plot graph on it.
// followdata_temp.php
(from where data is fetched)
$mysqli = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
//query to get data from the table
session_start();
//$pid = $_POST['patient_id'];
//echo $pid;
$query = sprintf("SELECT time, temp FROM heart_reating where patient_id='$pid' ") or die(mysql_error()); //$pid is where patient_id is declared in page.
//execute query
$result = $mysqli->query($query);
my html page
<html>
<head>
<title>ChartJS - Line</title>
<meta charset="utf-8"/>
<link href="css/default.css" rel="stylesheet">
</head>
<body>
<div class="chart-container">
<canvas id="line-chartcanvas"></canvas>
</div>
<!-- javascript -->
<script type="text/javascript" src="js2/jquery.min.js">
</script>
<script type="text/javascript" src="js2/Chart.min.js">
</script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js">
</script>
<script>
$(document).ready(function() {
/**
* call the data.php file to fetch the result from db table.
*/
$.ajax({
url : "/followdata_temp.php",
type : "GET",
success : function(data){
console.log(data);
var time = [];
var temp = [];
var len = data.length;
for (var i = 0; i < len; i++) {
time.push("" + data[i].time);
temp.push(data[i].temp);
}
//get canvas
var ctx = $("#line-chartcanvas");
var chartdata = {
labels : time,
datasets : [
{
label : "Temperature",
data : temp,
backgroundColor : "blue",
borderColor : "lightblue",
fill : false,
lineTension : 0,
pointRadius : 5
}
]
};
var chart = new Chart( ctx, {
type : "line",
data : chartdata
});
},
error : function(data) {
console.log(data);
}
});
});
</script>
</body>
</html>
I wanted plot graph by selecting patient id from select that is in phpmyadmin plot graph of it as (temp, time
)