0

My database table (test_12) is as follows:


S.I                   A              B               C              X        Y                        
SBI234      2.280130800000  2.339592225000  2.237112614000  2.296371308000  2.295634019000  
SBI316      1.832411563000  1.825578753000  1.830375097000  1.826226610000  1.831125007000  
SBI425      1.922666139000  1.937724567000  1.913369116000  1.941975395000  1.937476796000  
SBI567      1.926532891000  1.956353519000  1.978980200000  1.982052669000  2.001432287000 

My Code used to draw bar graph (Google chart) is as follows:

 <?php
$con = mysqli_connect("localhost","root","root123","myDB");
if ($con) {
    echo "connected";
    }
?>  
 <html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('current', {'packages':['bar']});
      google.charts.setOnLoadCallback(drawChart);

      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['S.I','A','B','C','X','Y']
         <?php
         $sql = "SELECT * FROM test_12";
         $fire = mysqli_query($con,$sql);
         while ($result = mysql_fetch_assoc($fire)){
             echo"['".$result['S.I']."',".$result['A'].",".$result['B'].", ".$result['C'].",".$result['X'].",".$result['Y']."]";
             }
          ?>
         ]);

     var options = {
          chart: {
            title: 'Google_Chart_Test',
            subtitle: 'Bar graph test',
          }
        };
           var chart = new google.charts.Bar(document.getElementById('columnchart_material'));

        chart.draw(data, google.charts.Bar.convertOptions(options));
      }
    </script>
  </head>
  <body>
    <div id="columnchart_material" style="width: 800px; height: 500px;"></div>
  </body>
</html>

The Result i am getting is attached kindly help me to solve the problem. Database connection is showing, graph shows null values on all axis. enter image description here

Thanks in advance.

  • Look at your output code. It's invalid; missing commas at the very least, and possibly quote marks. Your browser's Javascript console is certainly shouting errors at you. And do you really have a database column called "S.I"? Unlikely or unwise. – miken32 Feb 19 '20 at 20:52
  • Thanks, miken32 for reply. I don't find any missing commas in my script. As I also checked for syntax error which shows no error. Further database column called S.I in question is actually "name" for simplicity in question i changed it to S.I. Does the problem is because of the type of data, I'm not able to figure it out. Please help me to solve my problem. – user3732821 Feb 20 '20 at 06:42
  • Similar question, related to google chart, do not solve my problem. So please open this question. – user3732821 Feb 20 '20 at 06:49
  • ANYONE KNOW THE SOLUTION PLEASE REPLY ! – user3732821 Feb 25 '20 at 08:08

0 Answers0