Answer the question
In order to leave comments, you need to log in
How to display data in a Highcharts chart?
Good day to all. Help solve the problem. The graph is not drawn. can't get variable values. Although alert brought everything out.
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
/* 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 */
?>
Answer the question
In order to leave comments, you need to log in
Most likely you have my as a string, but you need an array.
Remove
and makeecho json_encode(array('dg' => $newArray));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question