Google Chart API 不适用于 PHP?



Google API 图表不接受我使用 php 回显的值,任何人都可以启发我做错了什么吗?

这是用户选择他们要查看的作业图表的地方:

<form class="form-horizontal form-select-chart" method="post" action="analytics.php">
                <select name="chartname">
                <?php
                    $sel_user = "select * from tbl_jobs";
                    $run_user = mysqli_query($con, $sel_user);
                    while($row = mysqli_fetch_assoc($run_user))
                      {
                          echo "<option value="" . $row['Job_ID'] . "">" . $row['Job_Name'] . "</option>";
                      }
                ?>
                </select>
                <br>
                <input type="submit" name="make_chart" value="Create the Chart" class="btn btn-primary" />
                </form>

以下是应处理数据的位置:

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
<?php
    if(isset($_POST['make_chart'])){
        $jid = mysqli_real_escape_string($con,$_POST['chartname']);
        $sel_user = "select * from tbl_jobs WHERE `ID` = '$jid'";
                    $run_user = mysqli_query($con, $sel_user);
                    while($row = mysqli_fetch_assoc($run_user))
                      {
                        $jname = $row['Job_Name'];
                        $overall_vacant = $row['Vacant'];   
                        $overall_filled = $row['Filled'];   
                      }
                      settype($overall_vacant, "integer");
                      settype($overall_filled, "integer");
    }
?>
  // Load the Visualization API and the corechart package.
  google.charts.load('current', {'packages':['corechart']});
  // Set a callback to run when the Google Visualization API is loaded.
  google.charts.setOnLoadCallback(drawChart);
  // Callback that creates and populates a data table,
  // instantiates the pie chart, passes in the data and
  // draws it.
  function drawChart() {
    // Create the data table.
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Topping');
    data.addColumn('number', 'Slices');
    data.addRows([
      ['Vacant Positions', <?php  echo $overall_vacant; ?>],
      ['Filled Positions', <?php  echo $overall_filled; ?>],
    ]);
    // Set chart options
    var options = {'title':'<?php echo $jname; ?>',
                   'width':400,
                   'height':300};
    // Instantiate and draw our chart, passing in some options.
    var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
    chart.draw(data, options);
  }
</script>

以下是要显示数据的位置:

    <?php 
        if(isset($_POST['make_chart'])){
        echo"<div align="center" id="chart_div"></div>"; 
        }
        unset($_POST['make_chart']));
    ?>

经过进一步调查,我发现我的MySQL查询有问题!我应该用"Job_ID"而不是"ID",这是两个不同的东西!

我的表格是这样的:

ID | Job_ID | Job_Name | Vacant | Filled
1      0      Overall    0        0

这反过来又导致了一个空白的图表!我真笨!感谢MECU的提醒!

相关内容

  • 没有找到相关文章

最新更新