0
<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"     type="text/javascript"></script>    
<script src='http://code.highcharts.com/highcharts.js' type='text/javascript'> </script>       
<script src='http://code.highcharts.com/modules/exporting.js' type='text/javascript'> </script>    

</head>

<body>

<?php
$con = mysql_connect('localhost', 'root', '123456') or die('Error connecting to server');
mysql_select_db("aplikace", $con); 

$SQL1 =     "SELECT * FROM data";

$result1 = mysql_query($SQL1);
$data1 = array();
while ($row = mysql_fetch_array($result1)) {
   $data1[] = $row['cas'];
}

$result2 = mysql_query($SQL1);
$data2 = array();
while ($row = mysql_fetch_array($result2)) {
   $data2[] = hexdec($row['pars_data']);
}


?>

<script type="text/javascript">
$(document).ready(function() {
    var chart = new Highcharts.Chart({
          chart: {
             renderTo: 'container',
             type: 'line'
          },

        title:  {
                    text: 'Comming Data'
                },

        xAxis:  {
                    categories: ['<?php echo join($data1, "','") ?>'],
                },

        yAxis:  {
                    min:0,

                },

        legend: {
                    layout: 'vertical',
                    backgroundColor: '#FFFFFF',
                    align: 'left',
                    verticalAlign: 'top',
                    x: 50,
                    y: 35,
                    floating: true,
                    shadow: true
                },

        plotOptions: {
                        column: {
                                    pointPadding: 0.2,
                                    borderWidth: 0
                                }
                    },

        series: [   {
                        name: 'Data',
                        data: ['<?php echo join($data2, "','") ?>'],
                       // pointStart: 0
                        //pointInterval
                    },


                ]
    });
});
</script>

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

大家好,我不知道我哪里有错误,请你帮我吗?在 X 轴上应该是来自 CAS 列的日期时间-> 它可以工作,但它不显示列 PARS_DATA。谢谢你的帮助,谢谢。

MySQL 表屏幕:

我看到的图表:

4

1 回答 1

0

您应该将您的日期时间字段转换为 unix 时间戳以便对其进行处理。所以 strtotime 函数是个好主意。

在您的代码中,请遵循以下内容:

 $result=mysql_query($sql)or die(mysql_error());
 if(mysql_num_rows($result)>0){
    while($row=mysql_fetch_array($result))
    {
        $uts=strtotime($row['time']); //convert to Unix Timestamp
        $date=date("l, F j, Y H:i:s",$uts); //standard template for draw chart

        echo $date . "\t" . $row['new_cost']. "\n";  //only this template work 
    }

$sql:你的 sql 查询文本。$结果:反馈。$row['new_cost']:我的成本字段。

有关更多详细信息,请点击链接

祝你好运

于 2013-04-11T04:12:39.133 回答