Highchart基本线

时间:2016-04-15 14:06:08

标签: php mysql json highcharts

http://www.highcharts.com/stock/demo/basic-line 我的json.php代码:

<?php
header("content-type: application/json");
define('HOST', 'localhost');
     define('USER', 'root');
     define('PASSWORD', 'Super_Password');
     define('NAME_BD', 'bd');
$connect = mysql_connect(HOST, USER, PASSWORD)
        or die("error"
               .mysql_error( ));
//    print ("no error");
mysql_select_db(NAME_BD, $connect)
         or die ("error"
                 .mysql_error( ));
$result = mysql_query("SELECT UNIX_TIMESTAMP(`Time`) * 1000 as datetime, `Current A` as A FROM `TT`")
     or die ("error".mysql_error( ));
//     echo "all good";
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$
}
//echo '('. json_encode(join($data, ',')) . ')';
echo ']);';
?>

但它不起作用:当我刷新页面时,我看不到图表

2 个答案:

答案 0 :(得分:1)

for ($i=0; $i<$count; $i++)
{
    echo '['.
        str_replace('"', "", json_encode($data[$i], JSON_HEX_APOS)) . ',' .
        str_replace('"', "", json_encode($datab[$i], JSON$ <----- What is this? Also missing 2 closing parenthesis ))
}

echo JSON$结束时,你有str_replace()这究竟是什么?更不用说你在最终json_encode()JSON$中错过了一个右括号,其中包括Polymer( { is: "paperspinner-dom", behaviors: [Polymer.NeonAnimationRunnerBehavior], properties: { opened: { type: Boolean }, animationConfig: { value: function() { return { 'showSpinner': { name: 'bounce-in-animation', node: this, timing: { duration: 1000 } }, 'hideSpinner': { name: 'fade-out-animation', node: this } } } } }, runSpinnerAnimation: function(){ this.playAnimation('showSpinner'); } });

总之,您似乎有一些需要解决的语法错误。

答案 1 :(得分:0)

oooo sory 缺少代码

$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 '('. json_encode(join($data, ',')) . ')';
echo ']);';
?>

在控制台0错误。