how to pass the array value through php in google chart api from my database values.

google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
   function drawChart() {
       var data = new google.visualization.DataTable();
        data.addColumn('string', 'year');
         data.addColumn('number', 'accounts');
           data.addRows([
          ['year',  'accounts'],
        ]);
        var data = google.visualization.arrayToDataTable([
          ['Year', 'Sales'],
          ['2004',  1000],
          ['2005',  1170],
          ['2006',  660],
          ['2007',  1030],
          ['2008',  1000],
          ['2009',  1370],
          ['2010',  800],
          ['2011',  1730],
          ['2012',  400],
          ['2013',  670],
          ['2014',  360],
          ['2015',  30]

        ]);
    var data = new google.visualization.DataTable();

how to pass the array values from my database dynamatically. please help me

If you use PHP then you can generate the above code. PHP will connect to MySQL, get the data and build the array, which you can then output to your webpage in the right spot.

function drawChart() {
      // Prepare the data
         data.addColumn('string', 'year');
         data.addColumn('number', 'accounts');
        var data = google.visualization.arrayToDataTable([
        ['name', 'gender'],
          <?php   while($row = mysql_fetch_array($result)){ ?>
          ['<?php echo $row['name']?>' , '<?php echo $row['gender']?>',],
          <?php } ?>
        ]);

sir, i using like that php scripts but its not working.

The problem is that your code leaves a comma at the end, which makes the JS array invalid.

sir, that mistake corrected but php file not include inside the js..

the error showing like that

function drawChart() {
      // Prepare the data
      <? 
      *Uncaught SyntaxError: Unexpected token < 


  what can i do for this..

The code you showed should be in a PHP script file. My guess is you just put that in a HTML file.

 data.addColumn('string', 'year');
         data.addColumn('number', 'accounts');
        var data = google.visualization.arrayToDataTable([
        ['year', 'accounts'],
         <?php   while($row1 = mysql_fetch_array($query_check_login_details1)){ ?>
          ['<?php echo $row1['created_date']?>' , '<?php echo $row1['value']?>',]
          <?php } ?>
        ]);

error file: `

data.addColumn('string', 'year');
         data.addColumn('number', 'accounts');
        var data = google.visualization.arrayToDataTable([
        ['year', 'accounts'],
         <br />
Uncaught SyntaxError: Unexpected token <
<font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.