Home forums Using CanvasJS Dynamic chart extra lines being added Reply To: Dynamic chart extra lines being added

#21839

Vulpe
Member

I don’t know if its of any use to you but here is the code the code that gets my data for me

<?php
     
    $dataPoints = array();
    
    try{
         // Creating a new connection.
        
        $link = new \PDO(   'mysql:host=192.168.0.89;dbname=light;charset=utf8mb4', 
                            'Jack', 
                            'Password', 
                            array(
                                \PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                                \PDO::ATTR_PERSISTENT => false
                            )
                        );
    	
        $handle = $link->prepare('select BTime, TSensor2 from bottomsensors'); 
        $handle->execute(); 
        $result = $handle->fetchAll(\PDO::FETCH_OBJ);
    		
        foreach($result as $row){
            array_push($dataPoints, array("x"=> strtotime($row->BTime)*1000, "y"=> $row->TSensor2));
        }
    	$link = null;
    }
    catch(\PDOException $ex){
        print($ex->getMessage());
    }
    echo json_encode($dataPoints, JSON_NUMERIC_CHECK);
?>