Jump to content

anyone help me with chartjs adn mysql, please

Recommended Posts

i want to build a bar chart with chartJS and database mysql with two different query, but bar chart not showing. can anyone help me to correct the code?

this my query and javascript:


$a = mysqli_query("select count(a) as total1 from tbl");

$b = mysqli_query("select count(b) as total2 from tbl");




<canvas id="chart"></canvas>




var ctx = document.getElementById("chart");

var chartdata = {

labels: 'CHART',

datasets: [{

label: "A",

data: [<?php while ($data1 = mysqli_fetch_array($a)) {echo '"''.$data1['total1'].'",';}?>],

backgroundColor: "#000000"


data: [<?php while ($data2 = mysqli_fetch_array($b)) {echo '"''.$data2['total2'].'",';}?>],

backgroundColor: "#ffffff"




var chart = new Chart(ctx, {

type: 'bar',

data: chartdata




Link to post
Share on other sites

thanks for replying, i'm new in this programming world. in browser page there is no error messages but chart not showing. and in developer tools, it shows error uncaught TypeError at chart.bundle.js and at line var chart = new Chart(ctx, {


Link to post
Share on other sites

Then that's where you need to look.  You need to look at the code that PHP is producing though, in your browser you need to view the source of the page and check to make sure that the Javascript code that you're having PHP output is valid code.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...