0

我正在使用 CodeIgniter 框架。在我的视图中,我有下表,它是通过控制器和模型从数据库中提取的数据自动填充的。我如何在 Google Charts 中表示它们?我对 AJAX、JSON 等的了解较少,因此我现在无法跳入 Google Chart API。有没有其他方法可以在 Google Charts 或类似的东西中表示它们?

<?php foreach ($query->result_array() as $row): { ?>
    <tr class="success">
        <td><?php echo $row['room_number'];?></td>
        <td><?php echo $row['start_date'];?></td>
        <td><?php echo $row['end_date'];?></td>
        <td><?php echo $row['pos_food_bev'];?></td>
        <td><?php echo $row['total'];?></td>
        <td><?php echo $row['payment_status'];?></td>
        <td><?php echo $row['guest_status'];?></td>
    </tr>    
<?php } ?>
<?php endforeach; ?>
4

1 回答 1

1

如果您提供更多信息会很好,这是我制作的条形图的一些代码,只是为了解释如何传递 php 数据以供 javascript 脚本使用

   <html>
  <head>



    <?php 
$hits = array(
    array("day"=>10,"count" =>53),
    array("day"=>11,"count" =>67),
    array("day"=>12,"count" =>85),
    array("day"=>13,"count" =>57),
    array("day"=>14,"count" =>65),
    array("day"=>15,"count" =>71),
    array("day"=>16,"count" =>85),
    array("day"=>17,"count" =>106),
    array("day"=>18,"count" =>55),
    array("day"=>19,"count" =>96),
    );
//this counter will be used later on the foreach
$counter = count($hits);?>
            <meta charset="utf-8">
            <script type="text/javascript" src="https://www.google.com/jsapi"></script>
            <script type="text/javascript">
              google.load("visualization", "1", {packages:["corechart"]});
              google.setOnLoadCallback(drawChart);
              function drawChart() {
                var data = google.visualization.arrayToDataTable([
                  ['Day',

 'Number of hits'],
              <?php foreach ($hits as $key =>$hit):?>

                <?php /*if the key is equal to the counter-1 it means we've reached
    the end of our array in that case the javascript array,
    won't have a comma at the end, or else it'll give a
    unexpected identifier error*/
                     if(($counter-1)==$key):?>
                  ['<?=$hit["day"]?>', <?=$hit["count"]?>]
                <?php else:?>
                  ['<?=$hit["day"]?>', <?=$hit["count"]?>],
                <?php endif;?>
                <?php endforeach;?>
            ]);

            var options = {
              title: 'Number of hits per day',
              hAxis: {title: 'Day', titleTextStyle: {color: 'blue'}}
            };

            var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
            chart.draw(data, options);
          }
        </script>
      </head>
      <body>
        <div id="chart_div" style="width: 900px; height: 500px;"></div>
      </body>
    </html>
于 2013-07-15T01:46:51.687 回答