This code:
//loop through the returned data
while ($row = mysqli_fetch_array($result)) {
$data1 = $data1 . '"'. $row['data1'].'",';
$data2 = $data2 . '"'. $row['data2'] .'",';
}
should be:
//loop through the returned data
while (!$sql->atEnd()) {
$data1 = $data1 . '"'. $sql->getColumnVal("
data1").'",';
$data2 = $data2 . '"'. $sql->getColumnVal("
data2") .'",';
$sql->moveNext()
}
I've attached a chart.js user registration chart example I created for another project you might get some ideas from.