(PHP,谷歌图表)饼图使用PHP页面中的数据

时间:2022-12-03 18:00:56

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

我是PHP的新手,我试图在我的PHP页面上创建饼图,但它没有显示任何内容。

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

这些是我的代码(我把所有代码放在HTML部分)

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

and this the piechart.php parts

这就是piechart.php的部分

<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.

饼图的结果只显示出像这样的大整个空白区域。

(PHP,谷歌图表)饼图使用PHP页面中的数据

I don't know why. Please help.

我不知道为什么。请帮忙。

1 个解决方案

#1


1  

the array values aren't being printed to JavaScript

数组值未打印到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

并且不认为需要if语句

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
    }
  ?>

]);

#1


1  

the array values aren't being printed to JavaScript

数组值未打印到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

并且不认为需要if语句

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
    }
  ?>

]);