1
1
123 1232014-10-16 19:27:12
PHP
123 123, 2014-10-16 19:27:12

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:
<?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

1 answer(s)
A
Alexander Aksentiev, 2014-10-24
@Sanasol

Most likely you have my as a string, but you need an array.
Remove
and make
echo json_encode(array('dg' => $newArray));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question