Hello I want in my chart to display the datetime, I made some search over the stack and I found similaer problems like this one but I could not understand how to fix that.
The part of the code that i believe i should change is the below..
<?php
$DB_NAME = 'project';
$DB_HOST = 'localhost';
$DB_USER = 'root';
$DB_PASS = 'smogi';
include_once 'header.php';
$view = ($_GET['view']);
$username2 =$_SESSION['username'];
$firstDate= $_POST['firstdatepicker'];
$lastDate= $_POST['lastdatepicker'];
$typeValue = ($_POST['typeValue']);
$startHour = ($_POST['startHour']);
$firstMin = ($_POST['firstMin']);
$lastHour = ($_POST['lastHour']);
$lastMin = ($_POST['lastMin']);
$firstTime = $startHour.':'.$firstMin.':00';
$lastTime = $lastHour.':'.$lastMin.':00';
$con = mysqli_connect('localhost','root','smogi','project');
/* Establish the database connection */
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$sql="SELECT sensorValue,datetime FROM sensors WHERE username='$view' AND datetime BETWEEN '$firstDate''$firstTime' AND '$lastDate''$lastTime' AND typeValue='$typeValue' ORDER BY datetime DESC";
$result = mysqli_query($con,$sql);
$rows = array();
$table = array();
$table['cols'] = array(
// Labels for your chart, these represent the column titles.
array('label' => 'Date Time', 'type' => 'date'),
array('label' => 'Sensor Value', 'type' => 'number')
);
/* Extract the information from $result */
foreach($result as $r) {
$temp = array();
// The following line will be used to slice the chart
$temp[] = array('v' => 'Date('.date('Y',strtotime($r['datetime'])).','.(date('n',strtotime($r['datetime'])) - 1).','.date('d',strtotime($r['datetime'])).',0,0,0)');
// Values of the each slice
$temp[] = array('v' => (int) $r['sensorValue']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
// convert data into JSON format
$jsonTable = json_encode($table);
//echo $jsonTable;
?>
<html>
<head>
<!--Load the Ajax API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(<?=$jsonTable?>);
var options = {
hAxis: {title: 'Date & Time'},
vAxis: {title: 'Sensor Values'},
title: 'Sensor Data',
is3D: 'true',
width: 900,
height: 600
};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<!--this is the div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>
My chart right now look like this ...
and what i want is instead of 1000,2000...5000 to display the datetime from the data that I am displaying.
My database table that contains the datetime is the below...
Can you help me please??? :)