【问题标题】:JSON data not showing in highstock candlestick chart using PHP and SQL使用 PHP 和 SQL 在 highstock 烛台图表中未显示 JSON 数据
【发布时间】:2019-09-16 21:57:28
【问题描述】:

我正在尝试显示highstock candlestick chart,但我无法实现。 我的网站在图表应显示的位置显示空白,但图表中没有显示任何内容。 如何修复它以显示图表?

我有两个脚本:

datachart.inc.php:

<?php
include '../dbh.php'; //It connects to the database

$sql = "SELECT * from table";
$result = $conn->query($sql);
$row = mysqli_fetch_array($result);

$data = array();
$count = 0;
while ($row=mysql_fetch_array($result))
{
  $newdate = strtotime($row['date']) * 1000; 
  $data[] = array($newdate, (float)$row['open'], (float)$row['high'], 
(float)$row['low'], (float)$row['close']);
  $count++;
}   
echo json_encode($data);
?>

index.htm:

<!DOCTYPE HTML>
<HTML>
   <BODY>
      <script>
      $(function() {
    $.getJSON('datachart.inc.php', function(data) {

    // create the chart
    chart = new Highcharts.StockChart({
        chart : {
            renderTo : 'container',
        },

        rangeSelector : {
            selected : 1
        },

        title : {
            text : 'Test Price'
        },

        series : [{
            type : 'candlestick',
            name : '',
            data : data,
            tooltip: {
                valueDecimals: 2
            },
            dataGrouping : {
                units : [
                    ['week', // unit name
                    [1] // allowed multiples
                ], [
                    'month', 
                    [1, 2, 3, 4, 6]]
                ]
            }
        }]
    });
    });
});
</script>

<div id="container" style="height: 250px; min-width: 250px"></div>

   </BODY>
</HTML>

点击here查看我的sql表的图片

【问题讨论】:

  • 您是否导入了highchart 正常工作所需的js, css 文件?
  • 控制台有错误吗?
  • @LakshanS 谢谢!我刚刚导入了文件。现在它显示一个空白图表。检查它imgur.com/a/CbfbVfB
  • 看到你在正确的轨道上。现在花点时间阅读文档并仔细为这些参数分配值。并检查控制台日志。
  • 我修好了!它现在正在工作!谢谢你:)

标签: php mysql sql json highcharts


【解决方案1】:

已解决:

1) 导入 javascript 文件

2) 删除“$row = mysqli_fetch_array($result);”

3) 将“while ($row=mysql_fetch_array($result))”改为“while ($row=mysqli_fetch_array($result))”

【讨论】:

    猜你喜欢
    • 2012-10-28
    • 2013-06-07
    • 1970-01-01
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多