Errror when trying to display SQL data from Microsoft SQL Server Management Studio to graph in canvasjs

Viewed 22

Heres the code:

I tried converting the code from mysql to mysqlsrv which has been a mess. I need to display values from the database onto a graph.

<?php
 require 'conn.php';
$dataPoints = array();
try{
     
    $link = $conn;

    $handle = "select Lolo_Setpoint, Hihi_Setpoint from Alarms";
    $result = sqlsrv_query($conn,$handle);
    
     
     
   
    foreach ((array) $result as $row)   
    {
        array_push($dataPoints, array("x"=> $row[0], "y"=> $row[1]));
    }
    $link = null;
}
catch(\PDOException $ex){
    print($ex->getMessage());
}
    
?>
<!DOCTYPE HTML>
<html>
<head>  
<script>
window.onload = function () {
 
var chart = new CanvasJS.Chart("chartContainer", {
    animationEnabled: true,
    exportEnabled: true,
    theme: "light1", // "light1", "light2", "dark1", "dark2"
    title:{
        text: "PHP Column Chart from Database"
    },
    data: [{
        type: "line", //change type to bar, line, area, pie, etc  
        dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
    }]
});
chart.render();
 
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</body>
</html>  

The result is just a blank screen

0 Answers
Related