我正在创建一个报告,我想在其中使用条形图显示我的数据,我浏览了一些博客、教程和一种打印方式;但是,现在我的需要是我想以百分比显示我的数据并打印出来,有人可以帮我吗?
这是我的代码:
<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,其中条形显示为固定宽度,我想根据查询创建的百分比来操纵条形宽度。提前致谢。