1

I'm new to PHP, I tried to create the pie chart on my PHP page but it shows nothing.

These are my codes (I put all codes in HTML section)

-> https://jsfiddle.net/1a4819vz/1/

and this the piechart.php parts

<script type="text/javascript">
  google.charts.load('current', {'packages':['corechart']});
  google.charts.setOnLoadCallback(drawChart);
  function drawChart() {

    var data = google.visualization.arrayToDataTable([
      ['Position', 'Applicant(s)'],

      <?php 
        for($i = 0; $i < $table_counter; $i++){
      ?> 

      [<?=$pos_chart[$i]?>, <?=$tapp_chart[$i]?>],

      <?php 
        }
      ?>

    ]);

    var options = {
      title: 'Pie chart of Total Applicants'
    };

    var chart = new google.visualization.PieChart(document.getElementById('piechart'));

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

<div id="piechart" style="width: 900px; height: 500px;"></div>

The result for pie chart turns out only the big whole white space like this.

enter image description here

I don't know why. Please help.

5
  • Show us how looks generated js code. Commented Jun 1, 2016 at 8:39
  • @nospor image updated Commented Jun 1, 2016 at 8:43
  • 1
    I asked for generated js code not image. You dynamically generate js code (some chart arrays) - I am asking for this. Commented Jun 1, 2016 at 8:45
  • I can see he is using google.visualization.PieChart library. Thus, this whole question is about how he misused the google library. Commented Jun 1, 2016 at 10:08
  • @David162795 yeah, I have no idea about what I have to do now... Commented Jun 1, 2016 at 10:54

1 Answer 1

1

the array values aren't being printed to JavaScript

need to use something like

<?=$pos_chart[$i]?>

or

<?php echo $tapp_chart[$i]?>

and don't see the need for the if statement

try this...

var data = google.visualization.arrayToDataTable([
  ['Position', 'Applicant(s)'],

  <?php
    for($i = 0; $i < $table_counter; $i++){
  ?>

  [<?="'".$pos_chart[$i]."'"?>,   <?=$tapp_chart[$i]?>],

  <?php
    }
  ?>

]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.