簡體   English   中英

高庫存圖表中的日期有誤

[英]Wrong date in highstock Chart

如何將正確的日期納入高庫存圖表? 我一直在滑塊中獲取1月到2月的幾個月(正確的范圍應該是7月到8月),這是不正確的。 在我的PHP中,我將數據庫中的日期/時間轉換為JavaScript時間戳,但仍然無法正常工作。 任何幫助將是巨大的,謝謝!

輸出數組: data.txt

當前高庫存圖表: 高線折線圖

PHP&JS和HTML:

 <?php $stmt = mysqli_prepare($con, "SELECT date, IFNULL(AT,'null') FROM test"); $result = array('date' => array(), 'AT' => array()); if ($stmt) { mysqli_stmt_execute($stmt); mysqli_stmt_bind_result($stmt, $date, $at); while (mysqli_stmt_fetch($stmt)) { $result['date'][] = $date; $result['AT'][] = (int)$at; $stamp = strtotime($date); // get unix timestamp $time = $stamp*1000; } mysqli_stmt_close($stmt); } ?> <!DOCTYPE html> <html > <!--<![endif]--> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="https://code.highcharts.com/stock/highstock.js"></script> <script src="https://code.highcharts.com/highcharts-more.js"></script> <script src="https://code.highcharts.com/modules/data.js"></script> <script> $(function(data) { $('#chart2').highcharts('StockChart', { //Stock chart - might need zones to match gauges rangeSelector : { buttons : [{ type : 'hour', count : 3, text : '3h' }, { type : 'day', count : 2, text : '2D' }, { type : 'week', count : 1, text : '1W' }, { type : 'month', count : 1, text : '1M' }, { type : 'all', count : 1, text : 'All' }], selected : 2, }, title: { text: 'Power' }, yAxis: [{ title: { text: 'Bat V' }, height: 400, lineWidth: 2, oposite: true }, { title: { // yAxis 1 ie secondary y-axis text: 'Solar V' }, //top: 200, height: 400, offset: 25, lineWidth: 2, oposite: false }], xAxis:{ type: <?php echo json_encode($time) ?>, }, series: [{ pointInterval: 24 * 3600 * 1000, type: 'line', data: <?php echo json_encode($result['AT']) ?> },], }); //end of stockchart graphic // end of get function }); // end of graphing function </script> </head> <body> <?php echo $time; ?> <br><br /><br /><br /> <div id="chart2" style="width:100%; height:600px;"></div> </body> </html> 

根據您的輸出數組:data.txt,其為[["2017-07-25 16:44",12],["2017-07-25 17:00",12],...]應該為[[1500981240000,12],[1500982200000,12],...]所以解決的方法是$result['date'][] = strtotime($date)*1000以毫秒為單位獲取unix時間戳

<?php
$stmt = mysqli_prepare($con, "SELECT date, IFNULL(AT,'null') FROM test");
    $result = array('date' => array(), 'AT' => array());
    if ($stmt) {
        mysqli_stmt_execute($stmt);
        mysqli_stmt_bind_result($stmt, $date, $at);
        while (mysqli_stmt_fetch($stmt)) {
            $result['date'][] = strtotime($date)*1000; // get unix timestamp in milliseconds
            $result['AT'][] = (int)$at;

           $stamp = strtotime($date); // get unix timestamp
           $time = $stamp*1000;       

        }
        mysqli_stmt_close($stmt);

    }

?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM