代码之家  ›  专栏  ›  技术社区  ›  hokletrain

highstock图表中的日期错误

  •  0
  • hokletrain  · 技术社区  · 7 年前

    我如何将正确的日期纳入我的高股价图?我一直在滑块中获取一月到二月的月份(正确的范围应该是七月到八月),这是不正确的。在我的PHP中,我将数据库中的日期/时间转换为JavaScript时间戳,但仍然不起作用。任何帮助都会很好,谢谢!

    输出阵列: data.txt

    当前高库存图表: highstock line chart

    <?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>
    1 回复  |  直到 7 年前
        1
  •  2
  •   Deep 3015    7 年前

    基于输出阵列:数据。txt,即 [["2017-07-25 16:44",12],["2017-07-25 17:00",12],...] 应该是这样的 [[1500981240000,12],[1500982200000,12],...] 所以修复是 $result['date'][] = strtotime($date)*1000

    <?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);
    
        }
    
    ?>