php array is not output in js

I’m trying to output an array to the Highcharts js graph. I’ve been working on this for two days now, and the array is output properly via echo and print_r in php code. But substituting the variable into the graph does not work.

Php code:

<?php 
$data = array();
$conn = mysqli_connect("localhost", "root", "", "fitness");
$sql=("SELECT weight fROM users  where id_users=".$_SESSION['id']." ");          
if($result = mysqli_query($conn, $sql)){
   while($row = mysqli_fetch_array($result)){
        $data[] = array($row['weight]);             
             }
              $ar =  json_encode($data);
    echo json_encode($ar);

} else{
    echo "<li><h2>The graph is empty</h2></li>";
}
mysqli_close($conn);
?>

I’m trying to substitute an array like this:

var weight = (<?php echo $ar;?>);

I’ve tried a bunch of combinations. the only code that output a variable to the graph is js in php, which is output via echo with an array variable in the graph. but it’s such nonsense that I gave it up. and the code itself output only one array value, although there are several in the database.