2016-04-18 3 views
0

http://www.highcharts.com/stock/demo/basic-lineHighstock zeichne nicht

Es ist mein Code für json.php

<?php 
header("content-type: application/json"); 
define('HOST', 'localhost'); 
    define('USER', 'root'); 
    define('PASSWORD', 'password'); 
    define('NAME_BD', 'bd'); 
$connect = mysql_connect(HOST, USER, PASSWORD) 
     or die("die" 
       .mysql_error()); 
mysql_select_db(NAME_BD, $connect) 
     or die ("wtf" 
       .mysql_error()); 
$result = mysql_query("SELECT UNIX_TIMESTAMP(`Time`) * 1000 as datetime, `Current A` as A FROM `Table`") 
    or die ("die".mysql_error()); 
while ($row = mysql_fetch_array($result)) { 
$data[] = $row['datetime']; 
$datab[] = $row['A']; 
} 
echo '?(' . "\n" . '['. "\n"; 
$count = count($data); 
for ($i=0; $i<$count; $i++) 
{ 
echo '['. str_replace('"', "", json_encode($data[$i], JSON_HEX_APOS)) . ',' . str_replace('"', "", json_encode($datab[$i], JSON_HEX_APOS)) .']' . ',' . "\n"; 
} 
echo ']);'; 
?> 

ich meine Seite und highstock aktualisieren nicht ziehen. Bitte hilf mir.

Es ist mein stock.html

<html> 
     <head> 
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
       <title>Highstock Example</title> 

       <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
       <style type="text/css"> 
${demo.css} 
       </style> 
       <script type="text/javascript"> 
$(function() { 

    $.getJSON('http://192.168.1.175/json.php', function (data) { 
     // Create the chart 
     $('#container').highcharts('StockChart', { 


      rangeSelector : { 
       selected : 1 
      }, 

      title : { 
       text : 'AAPL Stock Price' 
      }, 

      series : [{ 
       name : 'AAPL', 
       data : data 
      }] 
     }); 
    }); 

}); 

       </script> 
     </head> 
     <body> 
<script src="https://code.highcharts.com/stock/highstock.js"></script> 
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script> 

<div id="container" style="height: 400px; min-width: 310px"></div> 
     </body> 
</html> 

stock.html Anruf json.php aber wenn ein Refresh stock.html ich sehe nicht ziehen. Bitte helfen Sie mir

+0

Das Problem, dass Sie ist erstelle eine Zeichenfolge, die " sieht wie JSON aus "ist es aber nicht. Verwenden Sie die Arrays(), um eine Struktur zu erstellen, und dann json_encode(), um die Ausgabe zu drucken. –

+0

Thx i Unterstrich –

Antwort

0

Bitte versuchen Sie unter Code

in Ajax-Code

function drawGrap() 
{ 
    $.ajax({ 
     type: "POST", 
     url: 'graph.php', 
     data: '', 
     success: function(json) { 
      drawSalesChart(json); 
     } 
    }); 
} 

in graph.php

<?php 
if(!empty($data)) 
{ 
    foreach ($data as $d) 
    { 
     $time = strtotime($d['date']); 
     $date = date("Y-m-d",$time); 

     $graphData[$date][0] = 'Date.UTC('. date("Y",$time) .','. (date("m",$time)-1) .','. date("d",$time) .')'; 
     $graphData[$date][1] = $d['count']; 
    } 
}  
sort($graphData); 

//Convert result array to json format 
$jsonGraphData = json_encode($graphData); 
$jsonGraphData = str_replace('"', '', $jsonGraphData); 

echo $jsonGraphData; 
?> 

Nach Reaktion

function drawSalesChart(data) 
{ 
    $('#GraphID').css("height", "400px"); 
    $('#GraphID').highcharts('StockChart', { 
     title: { 
      text: 'Daily Sales' 
     }, 
     colors: ['#920000'], 
     navigator: { 
      enabled: false 
     }, 
     rangeSelector: { 
      selected: 5, 
      buttons: [ 
       { 
        type: 'week', 
        count: 1, 
        text: '1 Week' 
       }, 
       { 
        type: 'month', 
        count: 1, 
        text: '1 Month' 
       }, 
       { 
        type: 'month', 
        count: 3, 
        text: '3 Months' 
       }, 
       { 
        type: 'month', 
        count: 6, 
        text: '6 Months' 
       }, 
       { 
        type: 'year', 
        count: 1, 
        text: '1 Year' 
       }, 
       { 
        type: 'all', 
        text: 'All' 
       } 
      ], 
      buttonTheme: { 
       width: 100, 
       padding: 5, 
       style: { 
        color: '#000000' 
       } 
      } 
     }, 
     series: [{ 
       name: 'Kr', 
       type: 'area', 
       data: eval(data), 
       tooltip: { 
        valueDecimals: 2 
       }, 
       fillColor: { 
        linearGradient: { 
         x1: 0, 
         y1: 0, 
         x2: 0, 
         y2: 1 
        }, 
        stops: [ 
         [0, '#FF4848'], 
         [1, '#ffe1e1'], 
        ] 
       } 
      }] 
    }); 
} 
+0

Thx. Ich habe den Code korrigiert und verstanden. Das Programm verdient. –

+0

Bitte zögern Sie nicht UV diese Antwort, wenn es wirklich hilfreich für Sie ist .. :) –

+0

Analog dazu möchte ich hier realisieren: http://www.highcharts.com/stock/demo/compare aber ich don 't' t zeichnen. Hilf mir –

Verwandte Themen