skip to Main Content

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
Here is the database

2

Answers


  1. <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).

    Login or Signup to reply.
  2. It seems issue at your javascript code..it is not converting the php array to javascript properly.

    try this:

    <script type='text/javascript'>
    var ctx = document.getElementById('myChart').getContext('2d');
    var labels = '<?php echo json_encode($Timers); ?>';
    
    var myChart = new Chart(ctx, {
        type: 'line',
        data: {
            labels: labels,
            datasets: [{
                label: 'Time',
                data: [<?php echo $Wheights; ?>],
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search