I want to show data recieved from MySQL in Highchart.js graphic. For that, I'm using two textboxes which being entered to date informations. Finally, using a single button which calls function (chart.php). By the way, I'm getting date informations and sending to mysql.php with $.post method in the function. Then I want to get MySQL datas to show in Highchart.js. But program is giving me empty array. Actually, array have a lot of datas, because function(data) is showing datas in the ($.post).
chart.php
function zaman_al()
{
var baslangic=document.getElementById('rest_example_3').value;
var son=document.getElementById('rest_example_4').value;
if (baslangic=="" || son=="")
{
alert("Lütfen Tarih bilgisi Giriniz !!!");
}
else
{
baslangic = new Date(baslangic);
baslangic = baslangic.getTime();
son = new Date(son);
son= son.getTime();
if (son<=baslangic)
{
alert("Geçersiz Tarih Girişi !!!");
}
if (son>baslangic)
{
var veri={'baslama':(baslangic/1000),'bitirme':(son/1000)};
$.post('mysql.php',veri,
function(data)
{
alert(data);
$(function () {
$('#kku').highcharts({
chart: {
type: 'spline'
},
title: {
text: 'Snow depth at Vikjafjellet, Norway'
},
subtitle: {
text: 'Irregular time data in Highcharts JS'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { // don't display the dummy year
month: '%e. %b',
year: '%b'
},
title: {
text: 'Date'
}
},
yAxis: {
title: {
text: 'Snow depth (m)'
},
min: 0
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x:%e. %b}: {point.y:.2f} m'
},
plotOptions: {
spline: {
marker: {
enabled: true
}
}
},
series: [{
name: 'Winter 2007-2008',
// Define the data points. All series have a dummy year
// of 1970/71 in order to be compared on the same x axis. Note
// that in JavaScript, months start at 0 for January, 1 for February etc.
data: [
<?php
$veri=explode('"',$sonuc);
for ($i = 0; $i < count($veri); $i++)
{
if(($i%4)==1)
{
echo "[".$veri[$i].","; // time
}
if(($i%4)==3)
{
echo $veri[$i]."],
"; // sensor_value
}
};
?>
]
}]
});
});
});
}
}
}
Above code for button function. By the way.
chart.php
<b>Başlangıç Zamanı :</b> </td>
<td><input style="border-radius:15px" type="textbox" name="rest_example_3" id="rest_example_3" value="" /></td>
<td ><br><br><br></td>
</tr>
<tr>
<td><b>Bitiş Zamanı :</b> </td>
<td><input style="border-radius:15px" type="textbox" name="rest_example_4" id="rest_example_4" value="" /></td>
<td ><br><br><br></td>
</tr>
<tr>
<td ><br><br><br></td>
<td><input type="button" style="border-radius:15px; background-color:lightgreen; float:right" width="100" value="Get Chart" onClick="zaman_al()"> </td>
<td ><br><br><br></td>
</tr>
</table></center>
<div id="kku"></div>
When I sent to data mysql.php in the ($.POST), mysql.php is giving me notice:Undefined xxx.
By the way, mysql.php is follow as:
<?php
$baslangic =$_POST['baslama']; // -> notice: Undefined index: baslama
$son=$_POST['bitirme']; // -> notice: Undefined index: bitirme
//$baslangic=1445780257; -> correct result for it
//$son=1445780290; -> correct result for it
//echo $son;
//echo $baslangic;
//settype($son, "int");
//settype($baslangic, "int");
//echo gettype(1445780290);
//echo gettype($son);
$baglanti= new mysqli("localhost","root","","deneme_kou");
$sql = "SELECT zaman,sensor_deger FROM sensor WHERE zaman>='$baslangic' AND zaman<='$son'";
$res=mysqli_query($baglanti,$sql);
$result = array();
while( $row = mysqli_fetch_array($res))
{
$result[]=array($row["zaman"],$row["sensor_deger"]);
}
$sonuc=json_encode(array($result));
echo json_encode(array($result));
?>
When I wrote $baslangic=1445780257 $son=1445780290
; instead of $baslangic = $_POST['baslama']; $son=$_POST['bitirme']
, I can get correct result and show in highchart.js
.
Could you help me about this problem?