gpt4 book ai didi

php - 我可以单独从服务器端 PHP 填充 "Google Charts"吗?

转载 作者:行者123 更新时间:2023-11-29 13:44:25 26 4
gpt4 key购买 nike

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

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

最佳答案

如果您提供更多信息,那就太好了,这是我制作的条形图的一些代码,只是为了解释如何传递 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>

关于php - 我可以单独从服务器端 PHP 填充 "Google Charts"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17627209/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com