图表数据库数据连接

时间:2018-11-30 18:44:50

标签: php mysql mysqli highcharts

我将mysql数据库连接到Highstock图表时遇到问题 这是我的代码-运行时不显示任何内容

有人可以告诉我我做错了什么,还是可以通过数据库连接向我发送脚本示例? 我真的很感激

<!DOCTYPE HTML>
<html>
	 	<body>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="../../code/highstock.js"></script>
<script src="../../code/modules/exporting.js"></script>

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

		<script type="text/javascript">


<?php    $conn=mysqli_connect("localhost:3307","sampleuser","samplepass","sampledatabase");
if(!$conn)
{
	die("connection in error:".mysqli_connect_error());
}

$result=mysqli_query($conn,"Select time,open,close,high,low,volume From sampletable ");

while ($row = mysql_fetch_array($result)) {
   extract $row;
   $time *= 1000; // convert from Unix timestamp to JavaScript time
   $data[] = "[$time,$open,$close,$high,$low,$volume]";
}
?>

Highcharts.stockChart('container', {


        title: {
            text: 'AAPL stock price by minute'
        },

        rangeSelector: {
            buttons: [{
                type: 'hour',
                count: 1,
                text: '1h'
            }, {
                type: 'day',
                count: 1,
                text: '1D'
            }, {
                type: 'all',
                count: 1,
                text: 'All'
            }],
            selected: 1,
            inputEnabled: false
        },

        series: [{
            name: 'AAPL',
            type: 'candlestick',
            data: data,
            tooltip: {
                valueDecimals: 2
            }
        }]
    });



		</script>
	</body>
</html>

0 个答案:

没有答案