PHP實(shí)現(xiàn)動(dòng)態(tài)柱狀圖改進(jìn)版
本文實(shí)例分析了PHP實(shí)現(xiàn)動(dòng)態(tài)柱狀圖的改進(jìn)版。分享給大家供大家參考。具體分析如下:
前面已經(jīng)寫(xiě)過(guò)如果只做動(dòng)態(tài)柱狀圖的情況,其實(shí)原理還是很簡(jiǎn)單的。因?yàn)樽蛱煜挛缬行碌男枨?,今天上午又修改了一番,并將?shù)據(jù)根據(jù)編號(hào)不同分割顯示在表中。
下面把代碼粘出來(lái),方便以后自己查看,思路只是一時(shí)的火花,今天我想出來(lái)這么做,不一定下次還能想得到,也不用費(fèi)勁的去想,所以寫(xiě)成筆記是比較好的形式。
<!DOCTYPE html>
<?php
// 計(jì)算上一個(gè)月的今天
function last_month_today($time)
{
$last_month_time = mktime(date("G", $time), date("i", $time), date("s", $time), date("n", $time), 0, date("Y", $time));
$last_month_t = date("t", $last_month_time);
if ($last_month_t < date("j", $time)) {
return date("Y-m-t H:i:s", $last_month_time);
}
return date(date("Y-m", $last_month_time) . "-d", $time);
}
?>
<?php
include dirname(dirname(dirname(__FILE__))) . '/config.php';
$endDate = date('Y-m-d');
$date = strtotime($endDate);
$beginDate = last_month_today($date);
$sql = 'select count(*) from newpro where p_date>\'' . $beginDate . '\' and p_date<\'' . $endDate . '\'';
$d = db()->query($sql)->fetch(PDO::FETCH_NUM);
$sql2 = $sql . ' and is_pa_check_first=1 and is_pa_check_second=1 and is_pa_check_third=1';
$d2 = db()->query($sql2)->fetch(PDO::FETCH_NUM);
$sql3 = $sql . ' and is_pa_check_first=1';
$d3 = db()->query($sql3)->fetch(PDO::FETCH_NUM);
$sql4 = $sql . ' and is_pa_check_first=1 and is_pa_check_second=1';
$d4 = db()->query($sql4)->fetch(PDO::FETCH_NUM);
// 查詢每個(gè)人通過(guò)審核的情況:
$sqlab = 'select d_m,sum(sroce) as total_score,count(d_m) as total_number
from newpro
where is_pa_check_first=1
and is_pa_check_second=1
and is_pa_check_third =1
group by d_m';
$row = db()->query($sqlab)->fetchAll(PDO::FETCH_ASSOC);
?>
<html>
<head>
<meta charset="utf-8" />
<style>
div {
background-color: #669900;
width: 50px;
}
#div1 {
height: 200px;
}
#table td {
}
</style>
<script type="text/javascript" src="../../../js/jquery-1.7.2.min.js"></script>
</head>
<body>
<h3 align="center">近一個(gè)月總的情況</h3>
<table border="0" align="center" id="table1">
<caption>
<?php echo "時(shí)間:".$beginDate."至".$endDate?>
</caption>
<tr align="center" valign="bottom">
<td>
<p><?php echo $d[0]?></p>
<div id="div1"></div>
</td>
<td>
<p><?php echo $d3[0]?></p>
<div style="height:<?php $str=floor(($d3[0]/$d[0])*200); echo $str.'px'?>"></div>
</td>
<td>
<p><?php echo $d4[0]?></p>
<div style="height:<?php $str=floor(($d4[0]/$d[0])*200); echo $str.'px'?>"></div>
</td>
<td>
<p><?php echo $d2[0]?></p>
<div style="height:<?php $str=floor(($d2[0]/$d[0])*200); echo $str.'px'?>"></div>
</td>
</tr>
<tr align="center" valign="top">
<td><p>總計(jì)</p></td>
<td><p>一審?fù)ㄟ^(guò)</p></td>
<td><p>二審?fù)ㄟ^(guò)</p></td>
<td><p>審核通過(guò)</p></td>
</tr>
</table>
<h3 align="center">近一個(gè)月每個(gè)人的情況</h3>
<table border="0" width="100%">
<caption>每個(gè)人的完成情況如下表:</caption>
<!-- 因?yàn)榭偟牧袛?shù)比較長(zhǎng),如果顯示在一個(gè)表格中,數(shù)據(jù)會(huì)很擁擠,多的話根本就看不清楚。
所以需要將數(shù)據(jù)進(jìn)行分割,根據(jù)長(zhǎng)度進(jìn)行動(dòng)態(tài)的分割,顯示在多張表中。
-->
<?php
$arr = array_chunk($row,2,false);//2表示分割的單位長(zhǎng)度,false表示索引從0開(kāi)始
foreach($arr as $newRow){
$thStr = "<th style='background-color:#669900' width='110px' height='30px'>產(chǎn)品開(kāi)發(fā)編號(hào)</th>";
$trStr_total_score = "<tr align='center' style='background-color:silver' height='25px'><td>總分</td>";
$trStr_total_number = "<tr align='center' style='background-color:silver' height='25px'><td>總數(shù)量</td>";
$trStr_average_score = "<tr align='center' style='background-color:silver' height='25px'><td>平均分</td>";
$resultStr = "";
foreach ($newRow as $key => $value) {
// echo $key."=>".$value."<br/>";
$x = 0;
foreach ($value as $key2 => $value2) {
// echo $key2 . "=>" . $value2 . "<br/>";
if ($key2 == 'd_m') {
$thStr .= "<th style='background-color:#669900'>" . $value2 . "</th>"; // 表頭
} elseif ($key2 == 'total_score') {
$value2 = sprintf("%.2f", $value2); //保留2位小數(shù)
$trStr_total_score .= "<td>" . $value2 . "</td>";
$x += $value2;
} elseif ($key2 == 'total_number') {
$trStr_total_number .= "<td>" . $value2 . "</td>";
$x /= $value2;
}
}
$x = sprintf("%.2f",$x);
$trStr_average_score .= "<td>" . $x . "</td>";
}
echo "<table border='0' width='100%'>";
echo $thStr;
echo $trStr_total_number . "</tr>";
echo $trStr_total_score . "</tr>";
echo $trStr_average_score . "</tr>";
echo "</table>";
echo "<p height='150px'></p>";
}
?>
</table>
</body>
</html>
數(shù)據(jù)庫(kù)方便就不弄了,其實(shí),根據(jù)查詢的表名和字段名,是很容易建一個(gè)測(cè)試的數(shù)據(jù)表的。關(guān)鍵是思路,無(wú)論怎么變,思路是關(guān)鍵。
為了更加方便的了解代碼的效果,截個(gè)圖吧

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
- php打造智能化的柱狀圖程序,用于報(bào)表等
- PHP動(dòng)態(tài)柱狀圖實(shí)現(xiàn)方法
- JpGraph php柱狀圖使用介紹
- php報(bào)表之jpgraph柱狀圖實(shí)例代碼
- PHP 柱狀圖實(shí)現(xiàn)代碼
- php GD繪制24小時(shí)柱狀圖
- PHP中使用GD庫(kù)繪制折線圖 折線統(tǒng)計(jì)圖的繪制方法
- PHP制作3D扇形統(tǒng)計(jì)圖以及對(duì)圖片進(jìn)行縮放操作實(shí)例
- PHP實(shí)現(xiàn)繪制3D扇形統(tǒng)計(jì)圖及圖片縮放實(shí)例
- php+highchats生成動(dòng)態(tài)統(tǒng)計(jì)圖
- 在PHP上顯示JFreechart畫(huà)的統(tǒng)計(jì)圖方法
- PHP實(shí)現(xiàn)的曲線統(tǒng)計(jì)圖表示例
相關(guān)文章
PHP XML error parsing SOAP payload on line 1
PHP中GBK頁(yè)面調(diào)用WebService的編碼問(wèn)題:XML error parsing SOAP payload on line 12010-06-06
關(guān)于file_get_contents返回為空或函數(shù)不可用的解決方案
本篇文章是對(duì)file_get_contents返回為空或函數(shù)不可用的解決方案進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
php+jQuery實(shí)現(xiàn)的三級(jí)導(dǎo)航欄下拉菜單顯示效果
這篇文章主要介紹了php+jQuery實(shí)現(xiàn)的三級(jí)導(dǎo)航欄下拉菜單顯示效果,涉及php數(shù)組遍歷與jQuery事件響應(yīng)操作頁(yè)面元素變換等相關(guān)操作技巧,需要的朋友可以參考下2017-08-08

