Всем доброго времени суток. Помогите решить проблему. Не рисуется график т.к. не может получить значения переменных. Хотя alert все вывел.
JS:
$(function(){
$.getJSON("../ajax/get_weather_day.php", function(response){
draw(response.dg);
});
});
function draw(my)
{
alert(my);
$('#mychart').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Мониторинг температуры и влажности за день'
},
/* subtitle: {
text: 'Source: WorldClimate.com'
},*/
xAxis: {
categories: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
},
yAxis: {
title: {
text: 'Значение'
}
},
plotOptions: {
line: {
dataLabels: {
enabled: true
},
enableMouseTracking: false
}
},
series: [{
name: 'Температура',
data: my
}]
});
}
PHP:
<?php
/* SQL */
/* Connect */
try
{
$connection = new PDO("mysql:host=localhost;dbname=base","root","root");
}
catch (PDOException $e)
{
echo 'Connection error: ' . $e->getMessage();
}
/* /Connect */
/* Query */
$query = $connection->prepare("SELECT temperature FROM weather WHERE date >= CURDATE()");
$query->execute();
$result = $query->fetchAll();
if($query->rowCount() == 0)
{
echo "fail";
}
else
{
foreach ($result as $row)
{
$newArray[] = $row['temperature'];
}
$dg = implode(", ", $newArray);
echo json_encode(array('dg' => $dg));
}
/* /Query */
/* /SQL */
?>