gpt4 book ai didi

php - 如何使用PHP将MySQL数据打印成条形图

转载 作者:太空宇宙 更新时间:2023-11-03 12:30:57 24 4
gpt4 key购买 nike

我正在创建一个报告,我想在其中使用条形图显示我的数据我浏览了一些博客、教程和一种打印方式;但是,现在我的需要是我想以百分比显示我的数据并打印出来,有人可以帮我吗?

这是我的代码:

<style>
.clear{
clear:both;
}

.graphcont {
padding-top:10px;
color:#000;
font-weight:700;
float:left
}

.graph {
float:left;
margin-top:10px;
background-color:#cecece;
position:relative;
width:280px;
padding:0
}

.graph .bar {
display:block;
position:relative;
background-image:url(images/bargraph.gif);
background-position:right center;
background-repeat:repeat-x;
border-right:#538e02 1px solid;
text-align:center;
color:#fff;
height:25px;
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
line-height:1.9em
}

.graph .bar span {
position:absolute;
left:1em
}
</style>

</head>

<body>

<div id="container">

<?php
require("includes/dbconnect.php");

$getcen = mysql_query("SELECT count(*) AS totcen, center FROM `makhtab` WHERE center != '' GROUP BY center ORDER BY center") or die(mysql_error());

while ($mcent = mysql_fetch_array($getcen)) {
echo '<div class="rating"><div class="graphcont"><div class="graph"><strong class="bar" style="width:'.$mcent["totcen"].'%;">'.$mcent["totcen"].'</strong></div></div></div>
<div class="clear"></div>';
}
?>
</div>

上面的代码工作正常,但我想设置我的 div,其中栏显示为固定宽度,我想根据查询创建的百分比来操作栏宽度。提前致谢。

最佳答案

我对您的建议是使用外部轻量级框架来处理图表,它可以简化很多事情。

RazorFlow 非常好,试试吧。

关于php - 如何使用PHP将MySQL数据打印成条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15403864/

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