kiwari Posted April 23, 2018 Share Posted April 23, 2018 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: <?php $a = mysqli_query("select count(a) as total1 from tbl"); $b = mysqli_query("select count(b) as total2 from tbl"); ?> <body> <div> <canvas id="chart"></canvas> </div> <script> 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 }); </script> </body> Link to comment Share on other sites More sharing options...
justsomeguy Posted April 23, 2018 Share Posted April 23, 2018 The first thing to do is check for Javascript error messages, and look at the generated code that you created to see what all the browser sees. Link to comment Share on other sites More sharing options...
kiwari Posted April 24, 2018 Author Share Posted April 24, 2018 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 comment Share on other sites More sharing options...
justsomeguy Posted April 24, 2018 Share Posted April 24, 2018 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 comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now