2

i want to display multiple google gantt chart using while loop in php but this code only showing 1 gantt chart ( the first one). i want to display all the chart with loop so i will retrieve the data from database and show in every table row with chart

    <table>
    <?php 
      $i=0;
      while($i<4){
      echo"
        <script >
        google.charts.load('current', {'packages':['gantt']});
        google.charts.setOnLoadCallback(drawChart);

    function drawChart() {

      var data = new google.visualization.DataTable();
      data.addColumn('string', 'Task ID');
      data.addColumn('string', 'Task Name');
      data.addColumn('string', 'Resource');
      data.addColumn('date', 'Start Date');
      data.addColumn('date', 'End Date');
      data.addColumn('number', 'Duration');
      data.addColumn('number', 'Percent Complete');
      data.addColumn('string', 'Dependencies');

      data.addRows([
        ['2014Spring', 'Spring 2014', 'spring',
         new Date(2014, 2, 22), new Date(2014, 5, 20), null, 100, null],
        ['2014Summer', 'Summer 2014', 'summer',
         new Date(2014, 1, 12), new Date(2014, 2, 20), null, 100, null],
         ['2015Winter', 'Winter 2015', 'winter',
         new Date(2015, 11, 21), new Date(2016, 2, 21), null, 0, null],

      ]);

      var options = {
        height: 200,
        gantt: {
          trackHeight: 25
        }
      };

          var chart = new       google.visualization.Gantt(document.getElementById('chart_div$i'));

      chart.draw(data, options);
    }
  </script>

  <tr>


     <td>    Hello </td>
      <td id='chart_div$i'></td>

      </tr>

      ";
      $i++;
      }
    ?>

</table>

please help me out an dpoint out where i am doing wrong thanks

adeel pervaiz
  • 65
  • 2
  • 7
  • it could be a known issue with drawing multiple _material_ charts. not sure if a 'gantt' chart is a _material_ chart but since it isn't included with _corechart_... -- you might try using a frozen version `'44'`, `'43'`, or lower instead of `'current'` -- to my knowledge, this applies to IE and might also require a META tag, see --> [Drawing Multiple Material Charts](http://stackoverflow.com/a/32907208/5090771) – WhiteHat Mar 24 '16 at 23:11

0 Answers0