I’m trying to add a graph to my data. This data is imported from phpmyadmin. The data goes through, i have the tables under it. When I try to add the data, I get an error because it translates my php to [<br />
.
<script type='text/javascript'>
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [<?php echo $Timers; ?>],
datasets: [{
label: 'Time',
data: [<?php echo $Wheights; ?>],
the php
while ($stelling = mysqli_fetch_array($records1)){
$Timer = date('M, Y', strtotime($stelling['Timer']));
$Wheight = $stelling['Wheight'];
$Title = $stelling['Title'];
$Timers = '';
$Wheights = '';
$Titles = '';
$Timers = $Timers.'"'.$Timer.'",';
$Wheights = $Wheights.$Wheight.',';
$Titles = $Titles.$Title.',';
$Timers = trim($Timers, ",");
$Wheights = trim($Wheights, ",");
$Titles = trim($Titles, ",");
}include ("script/graph.php");
}
This is the error:
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [<br />
< etc
I expect the data to come through the chart.js to form a graph
2
Answers
<br />
is part of php error, that doesn’t show completely in rendered html.if you want to see actual error, you can see page source (Ctrl+u).
It seems issue at your javascript code..it is not converting the php array to javascript properly.
try this: