Ⅰ html css設計問題 求高手教教我
我知道怎麼樣可以弄成條形圖,但是php讀取這個不會。弄成條形的很簡單,創建一個DIV,用CSS添加一個背景色,然後設置寬度,寬度的單位用百分比就OK了。
Ⅱ PHP中圖像處理怎麼寫一個折線統計圖
在PHP中,有一些簡單的圖像函數是可以直接使用的,但大多數要處理的圖像,都需要在編譯PHP時加上GD庫。除了安裝GD庫之外,在PHP中還可能需要其他的庫,這可以根據需要支持哪些圖像格式而定。GD庫可以網上免費下載,不同的GD版本支持的圖像格式不完全一樣,最新的GD庫版本支持GIF、JPEG、PNG、WBMP、XBM等格式的圖像文件,此外還支持一些如FreeType、Type 1等字體庫。通過GD庫中的函數可以完成各種點、線、幾何圖形、文本及顏色的操作和處理,也可以創建或讀取多種格式的圖像文件。
在PHP中,通過GD庫處理圖像的操作,都是先在內存中處理,操作完成以後再以文件流的方式,輸出到瀏覽器或保存在伺服器的磁碟中。創建一個圖像應該完成如下所示的4個基本步驟。
(1)創建畫布:所有的繪圖設計都需要在一個背景圖片上完成,而畫布實際上就是在內存中開辟的一塊臨時區域,用於存儲圖像的信息。以後的圖像操作都將基於這個背景畫布,該畫布的管理就類似於我們在畫畫時使用的畫布。
(2)繪制圖像:畫布創建完成以後,就可以通過這個畫布資源,使用各種畫像函數設置圖像的顏色、填充畫布、畫點、線段、各種幾何圖形,以及向圖像中添加文本等。
(3)輸出圖像:完成整個圖像的繪制以後,需要將圖像以某種格式保存到伺服器指定的文件中,或將圖像直接輸出到瀏覽器上顯示給用戶。但在圖像輸出之前,一定要使用header()函數發送Content-type通知瀏覽器,這次發送的是圖片不是文本。
(4)釋放資源:圖像被輸出以後,畫布中的內容也不再有用。出於節約系統資源的考慮,需要及時清除畫布佔用的所有內存資源。
php中用GD繪制折線圖,代碼如下:
Class Chart{
private $image; // 定義圖像
private $title; // 定義標題
private $ydata; // 定義Y軸數據
private $xdata; // 定義X軸數據
private $seriesName; // 定義每個系列數據的名稱
private $color; // 定義條形圖顏色
private $bgcolor; // 定義圖片背景顏色
private $width; // 定義圖片的寬
private $height; // 定義圖片的長
/*
* 構造函數
* String title 圖片標題
* Array xdata 索引數組,X軸數據
* Array ydata 索引數組,數字數組,Y軸數據
* Array series_name 索引數組,數據系列名稱
*/
function __construct($title,$xdata,$ydata,$seriesName) {
$this->title = $title;
$this->xdata = $xdata;
$this->ydata = $ydata;
$this->seriesName = $seriesName;
$this->color = array('#DC', '#B', '#EDB', '#DDDF', '#CBE', '#E', '#FF', '#FFF', '#AFC');
}
/*
* 公有方法,設置條形圖的顏色
* Array color 顏色數組,元素取值為'#DC'這種形式
*/
function setBarColor($color){
$this->color = $color;
}
/*
* 繪制折線圖
*/
public function paintLineChart() {
$ydataNum = $this->arrayNum($this->ydata); // 取得數據分組的個數
$max = $this->arrayMax($this->ydata); // 取得所有呈現數據的最大值
$max = ($max > )? $max : ;
$multi = $max/; // 如果最大數據是大於的則進行縮小處理
$barHeightMulti = .; // 條形高縮放的比例
$lineWidth = ;
$chartLeft = (+strlen($max))*; // 設置圖片左邊的margin
$lineY = ; // 初始化條形圖的Y的坐標
// 設置圖片的寬、高
//$this->width = $lineWidth*count($this->xdata) + $chartLeft - $lineWidth/.;
$margin = ; // 小矩形描述右邊margin
$recWidth = ; // 小矩形的寬
$recHeight = ; // 小矩形的高
$space = ; // 小矩形與條形圖的間距
$tmpWidth = ;
// 設置圖片的寬、高
$lineChartWidth = $lineWidth*count($this->xdata) + $chartLeft - $lineWidth/. ;
// 兩個系列數據以上的加上小矩形的寬
if($ydataNum > ) {
$tmpWidth = $this->arrayLengthMax($this->seriesName)**/ + $space + $recWidth + + $margin;
}
$this->width = $lineChartWidth + $tmpWidth;
$this->height = ;
$this->image = imagecreatetruecolor($this->width ,$this->height); // 准備畫布
$this->bgcolor = imagecolorallocate($this->image,,,); // 圖片的背景顏色
// 設置條形圖的顏色
$color = array();
foreach($this->color as $col) {
$col = substr($col,,strlen($col)-);
$red = hexdec(substr($col,,));
$green = hexdec(substr($col,,));
$blue = hexdec(substr($col,,));
$color[] = imagecolorallocate($this->image ,$red, $green, $blue);
}
// 設置線段的顏色、字體的顏色、字體的路徑
$lineColor = imagecolorallocate($this->image ,xcc,xcc,xcc);
$fontColor = imagecolorallocate($this->image, x,xf,xf);
$fontPath = 'font/simsun.ttc';
imagefill($this->image,,,$this->bgcolor); // 繪畫背景
// 繪畫圖的分短線與左右邊線
for($i = ; $i < ; $i++ ) {
imageline($this->image,$chartLeft-,$lineY-$barHeightMulti*$max//$multi*$i,$lineChartWidth,$lineY-$barHeightMulti*$max//$multi*$i,$lineColor);
imagestring($this->image,,,$lineY-$barHeightMulti*$max//$multi*$i-,floor($max/*$i),$fontColor);
}
imageline($this->image,$chartLeft-,,$chartLeft-,$lineY,$lineColor);
imageline($this->image,$lineChartWidth-,,$lineChartWidth-,$lineY,$lineColor);
$style = array($lineColor,$lineColor,$lineColor,$lineColor,$lineColor,$this->bgcolor,$this->bgcolor,$this->bgcolor,$this->bgcolor,$this->bgcolor);
imagesetstyle($this->image,$style);
// 繪制折線圖的分隔線(虛線)
foreach($this->xdata as $key => $val) {
$lineX = $chartLeft + + $lineWidth*$key;
imageline($this->image,$lineX,,$lineX,$lineY,IMG_COLOR_STYLED);
}
// 繪畫圖的折線
foreach($this->ydata as $key => $val) {
if($ydataNum == ) {
// 一個系列數據時
if($key == count($this->ydata) - ) break;
$lineX = $chartLeft + + $lineWidth*$key;
$lineY = $lineY-$barHeightMulti*($this->ydata[$key+])/$multi;
// 畫折線
if($key == count($this->ydata) - ) {
imagefilledellipse($this->image,$lineX+$lineWidth,$lineY,,,$color[]);
}
imageline($this->image,$lineX,$lineY-$barHeightMulti*$val/$multi,$lineX+$lineWidth,$lineY,$color[]);
imagefilledellipse($this->image,$lineX,$lineY-$barHeightMulti*$val/$multi,,,$color[]);
}elseif($ydataNum > ) {
// 多個系列的數據時
foreach($val as $ckey => $cval) {
if($ckey == count($val) - ) break;
$lineX = $chartLeft + + $lineWidth*$ckey;
$lineY = $lineY-$barHeightMulti*($val[$ckey+])/$multi;
// 畫折線
if($ckey == count($val) - ) {
imagefilledellipse($this->image,$lineX+$lineWidth,$lineY,,,$color[$key%count($this->color)]);
}
imageline($this->image,$lineX,$lineY-$barHeightMulti*$cval/$multi,$lineX+$lineWidth,$lineY,$color[$key%count($this->color)]);
imagefilledellipse($this->image,$lineX,$lineY-$barHeightMulti*$cval/$multi,,,$color[$key%count($this->color)]);
}
}
}
// 繪畫條形圖的x坐標的值
foreach($this->xdata as $key => $val) {
$lineX = $chartLeft + $lineWidth*$key + $lineWidth/ - ;
imagettftext($this->image,,-,$lineX,$lineY+,$fontColor,$fontPath,$this->xdata[$key]);
}
// 兩個系列數據以上時繪制小矩形及之後文字說明
if($ydataNum > ) {
$x = $lineChartWidth + $space;
$y = ;
foreach($this->seriesName as $key => $val) {
imagefilledrectangle($this->image,$x,$y,$x+$recWidth,$y+$recHeight,$color[$key%count($this->color)]);
imagettftext($this->image,,,$x+$recWidth+,$y+$recHeight-,$fontColor,$fontPath,$this->seriesName[$key]);
$y += $recHeight + ;
}
}
// 繪畫標題
$titleStart = ($this->width - .*strlen($this->title))/;
imagettftext($this->image,,,$titleStart,,$fontColor,$fontPath,$this->title);
// 輸出圖片
header("Content-Type:image/png");
imagepng ( $this->image );
}
/*
* 私有方法,當數組為二元數組時,統計數組的長度
* Array arr 要做統計的數組
*/
private function arrayNum($arr) {
$num = ;
if(is_array($arr)) {
$num++;
for($i = ; $i < count($arr); $i++){
if(is_array($arr[$i])) {
$num = count($arr);
break;
}
}
}
return $num;
}
/*
* 私有方法,計算數組的深度
* Array arr 數組
*/
private function arrayDepth($arr) {
$num = ;
if(is_array($arr)) {
$num++;
for($i = ; $i < count($arr); $i++){
if(is_array($arr[$i])) {
$num += $this->arrayDepth($arr[$i]);
break;
}
}
}
return $num;
}
/*
* 私有方法,找到一組中的最大值
* Array arr 數字數組
*/
private function arrayMax($arr) {
$depth = $this->arrayDepth($arr);
$max = ;
if($depth == ) {
rsort($arr);
$max = $arr[];
}elseif($depth > ) {
foreach($arr as $val) {
if(is_array($val)) {
if($this->arrayMax($val) > $max) {
$max = $this->arrayMax($val);
}
}else{
if($val > $max){
$max = $val;
}
}
}
}
return $max;
}
/*
* 私有方法,求數組的平均值
* Array arr 數字數組
*/
function arrayAver($arr) {
$aver = array();
foreach($arr as $val) {
if(is_array($val)) {
$aver = array_merge($aver,$val);
}else{
$aver[] = $val;
}
}
return array_sum($aver)/count($aver);
}
/*
* 私有方法,求數組中元素長度最大的值
* Array arr 字元串數組,必須是漢字
*/
private function arrayLengthMax($arr) {
$length = ;
foreach($arr as $val) {
$length = strlen($val) > $length ? strlen($val) : $length;
}
return $length/;
}
// 析構函數
function __destruct(){
imagedestroy($this->image);
}
}
測試代碼如下:
$xdata = array('測試一','測試二','測試三','測試四','測試五','測試六','測試七','測試八','測試九');
$ydata = array(array(,,,,,,,,),array(,,,,,,,,));
$color = array();
$seriesName = array("七月","八月");
$title = "測試數據";
$Img = new Chart($title,$xdata,$ydata,$seriesName);
$Img->paintLineChart();
效果圖如下:
到此代碼結束。
下面給大家介紹php中GD庫的一些簡單使用
今天了解了一些GD庫的簡單使用,現在稍微做一下總結!
GD庫是什麼?,graphic device,圖像工具庫,gd庫是php處理圖形的擴展庫,gd庫提供了一系列用來處理圖片的API,使用GD庫可以處理圖片,或者生成圖片。 在網站上 GD庫通常用來生成縮略圖或者用來對圖片加水印或者對網站數據生成報表。
php並不局限於輸出HTML文本。php通過使用GD擴展庫還能用來動態輸出圖像,例如文字按鈕、驗證碼、數據統計圖等。哈可以輕松地編輯圖像,力圖處理縮略圖和為圖片添加水印等,具有強大的圖像處理能力。
首先我們來說下GD庫,繪制個簡單圖形的一些步驟:
1、首先是創建畫布,此處我們利用imagecreatetruecolor函數,也可以利用imagecreate,區別在於前者創建了一個真彩圖像,後者創建了一個基於調色板的圖像
$img=imagecreatetruecolor(100,100),其中有兩個參數分別對應,我們創建的圖像的寬和高
2、設置一些必要的"染料盒"
其實就是定義一些之後會用到的填充顏色,此處我們統一定義在這個位置,此處我們利用imagecolorallocate函數
$white=imagecolorallocate($img,0xFF,0xFF,0xFF)或者可以使用RGB的顏色命名方式 如$white=imagecolorallocate($img,255,255,255);
$gray = imagecolorallocate($img, 0xC0, 0xC0, 0xC0);
$darkgray = imagecolorallocate($img, 0x90, 0x90, 0x90);
$navy = imagecolorallocate($img, 0x00, 0x00, 0x80);
$darknavy = imagecolorallocate($img, 0x00, 0x00, 0x50);
$red = imagecolorallocate($img, 0xFF, 0x00, 0x00);
$darkred = imagecolorallocate($img, 0x90, 0x00, 0x00);
$black=imagecolorallocate($img,0x00,0x00,0x00);
此處我們定義多一些所需要的顏色
3、填充區域顏色,可以簡單的理解為填充圖片的背景顏色,利用imagefill函數
imagefill($img,0,0,$white),此處的0 0表示從坐標x y處開始填充背景色
4、繪制圖形,例如繪制餅狀圖,所需要的是imagefilledarc函數
imagefilledarc()的參數相對來說較多,形如imagefilledarc($img,50,$i,100,50,0,45,$red,IMG_ARC_PIE);
其中分別表示以red顏色字img圖像上繪制一個以50,$i為起點,以0 45角度這個范圍內繪制弧線
5、期間我們還可以添加一些說明問題,比如水平的添加一個字元串,利用 imagestring($img,1,20,40,"hello,world!",$red),表示在img圖片中以20 40為坐標,寫上一個紅色的hello,world!字樣
6、就是講圖像輸出
首先要告之瀏覽器要以何種圖片格式輸出,例如以png輸出,則使用header("Content-type:image/png");
其次 將圖片輸出到瀏覽器中,imagepng($img);
最後,銷毀圖片,即釋放該圖片存儲所佔用的內存 imagedestroy(img);,
Ⅲ php投票的條形柱狀圖和百分比該怎麼做
這樣的圖可以在Excel中製作插入→圖表→柱形圖→選擇子圖表類型中的那個三維堆積柱形圖,然後點下一步,按照提升就可以製作了,要先把數據輸入在表格內。
Ⅳ 看PHP如何生成的條形碼
條形碼不能判斷產品的真偽,條形碼是中國物品編碼中心給到注冊企業並由企業自行對公司產品進行編碼的,用微信掃常見的生活用品一般能掃出來,但工業用品很多就掃不出。
主要是跟微信合作的條碼搜入公司(貌似是靈**拍)並沒有及時搜入該產品的條形碼。
我查*這個軟體稍微好一點,搜入的比較全。
至於產品真偽,這個需要自己判斷了。
Ⅳ 在PHP中如何做出一個投票系統
這是一個簡單的投票程序,對於剛學PHP和朋友來說是一個很不錯的入門程序。在這里給大家介紹一下,希望能對朋友們有所幫助。該系統是由以下四個文件組成的:有HTML調查表單的survey.htm,實現調查功能的survey.php,記錄調查項目的data.txt和記錄調查結果的survey.txt.其中data.txt和survey.txt我們可以用NOTEPAD分別創建之,並傳到程序目錄下。文件data.txt中存的是要進行調查的項目,注意每個項目應佔一行;而survey.txt則可以是一個什麼內容也沒有的空文件。Survey.htm的代碼可以如如下所示:<html>
<head>
<title>survey</title>
</head>
<body>
<form method="POST" action="survey.php">
<p><input type="radio" value="0" name="vote">調查項目一</p>
<p><input type="radio" name="vote" value="1">調查項目二</p>
<p><input type="radio" name="vote" value="2">調查項目三</p>
<p><input type="radio" name="vote" value="3">調查項目四</p>
<p><input type="radio" name="vote" value="4">調查項目五</p>
<p><input type="hidden" name="go" value="1">
<p><input type="submit" value="提交" name="B1"></p>
<a href="survey.php?result=1">查看結果</a>
</form>
</body>
</html>注意文件data.txt中的調查項目與上面的調查項目在個數和排列順序必須保持一致,否則會出錯或調查的結果不準確。同時為了將調查結果顯示成條形圖形式,應該准備若干種不同顏色的條形圖片。如:0.gif,1.gif,2.gif,3.gif,4.gif等.以下是實現調查功能的survey.php代碼:<?
$data="data.txt";
$votes="survey.txt";
$dataf=file($data); /*讀出調查項目文件中的項目*/
$file_votes=fopen($votes, "r");
$line_votes=fgets($file_votes, 255); /*讀出已經記錄的調查結果*/
fclose($file_votes);
$single_vote=explode("|", $line_votes); /* 並將數據按指定的字串切開,再將字串傳回到數組變數中 */
if ($result!=1) /*如果已經接受了調查*/
{
$file_votes=file($votes, "r");
if ($REMOTE_ADDR == $file_votes[1]) /*檢查是不是同一個人*/
{
echo "<center><font color=red>您已投過票了,謝謝您的參與!</font></center>";
exit;
}
/*如果IP不重復,則執行以下程序*/
$ficdest=fopen($votes, "w");
for ($i=0; $i<=count($dataf)-1; $i++)
{
if ($i == $vote)
{ /*判斷選擇了哪個項目*/
$single_vote[$i]+=1;
}
fputs($ficdest, "$single_vote[$i]|"); /*將數據寫迴文件*/
}
fputs($ficdest, "\n$REMOTE_ADDR");/* //寫入投票者IP*/
fclose($ficdest);
$result=1; /*投票成功*/
}
/*寫入投票結果後並顯示投票結果*/
if ($result==1)
{
echo "<table cellpadding=10>";
for ($i=0; $i<=count($dataf)-1; $i++)
{
/*取得投票總數*/
$tot_votes+=$single_vote[$i];
}
for ($i=0; $i<=count($dataf)-1; $i++)
{
$imag=strval($i).".gif";/*判斷用哪種條形圖片來顯示統計結果*/
$stat[$i]=$single_vote[$i]/$tot_votes*100; /*計算百分比*/
$scla=$stat[$i]*5;/*條形圖和放大倍數,這里是安百分數的5倍的相素的寬度來顯示的*/
echo "<tr><td><li><font face=Verdana size=2>";
echo "$dataf[$i]</font></td><td align=left><font face=Verdana size=2>";
echo "<img src=\"$imag\" height=20 width=$scla align=middle> ";/*輸出條形碼圖*/
printf("%.1f", "$stat[$i]");
echo "%</font></td><td align=center><font face=Verdana size=2>";
/*輸出本欄目投票數*/
echo "$single_vote[$i]</font>";
echo "</td></tr>";
}
echo "</table><p>";
echo "<font face=Verdana size=2>總投票數:$tot_votes </font>";
}
?>說明: 在這里為了防止一人多投是採用記錄最近的一位投票者的IP的方法來實現的,而最近的一位投票的IP地址是WEB客戶機在對伺服器發出請求時存儲在環境變數REMOTE_ADDR中的。我也是一個初學者,關於這篇文章可能有許多錯誤和不當之處歡迎各位提出寶貴的意見和建議。謝謝!
Ⅵ PHP怎麼做條形統計圖
以下的推薦使用的php圖形函數庫:
1. JpGraph
是一個面向對象圖形創建函數庫。可用它來生成柱狀圖,餅狀圖,甘特圖,網狀圖等常用到的一些圖形。支持的圖片格式有GIF,JPG和PNG。
下載地址:http://jpgraph.net/download/
2. pChart
pChart是一個基於GD library(圖形處理函數庫)開發的PHP圖表製作開源項目。支持多種圖表類型。
下載地址:http://pchart.sourceforge.net/download.php
3. Highcharts
Highcharts是一個純JavaScript編寫的圖表庫,為您的網站或Web應用程序提供直觀,互動式圖表。
Highcharts目前支持線形圖、區塊圖、柱形圖、條形圖、餅圖和散點圖等類型。
下載地址:http://www.highcharts.com/download
Ⅶ 誰能告訴我用於統計分析的條形圖和餅狀圖的插件啊(php的)
直接用現成的FLASH,有柱狀圖,線圖,餅圖等豐富多彩的類型。推薦open flash chart . 請看演示
Ⅷ php建站 jpgraph 顯示圖像亂碼的問題,
汗,看看那啥gbk啦utf-8啦什麼的,你懂的……
今天我就寫了一個採集功能,難怪採集不到,丫的是亂碼,原來字元集不一致!
反正我遇到的一切亂碼情況都是因為字元集,難道說還有第二種方法可製造亂碼?反正我不信。
Ⅸ php生成條形碼的圖片的實例詳解
php生成條形碼的圖片的實例詳解
因為用戶的需要
寫了一個條形碼;用php生成一個條形碼的圖片
這個大家應該比我要好很多的吧,在自己項目的根目錄下建立一個測試文件(直接把下面的代碼放進去運行一下看看,我也是抄襲別人的),在實際的項目中你可以將下面的代碼封裝到一個公共類文件下的一個函數,然後調用。
class
testinfo{
function
UPCAbarcode($code)
{
$trans_code
=
$code;
$lw
=
2.2;
$hi
=
40;
$Lencode
=
array('0001101','0011001','0010011','0111101','0100011',
'0110001','0101111','0111011','0110111','0001011');
$Rencode
=
array('1110010','1100110','1101100','1000010','1011100',
'1001110','1010000','1000100','1001000','1110100');
$ends
=
'101';
$center
=
'01010';
/*
Compute
the
EAN-13
Checksum
digit
*/
$ncode
=
'0'.$code;
$even
=
0;
$odd
=
0;
for
($x=0;$x<12;$x++)
{
if
($x
%
2)
{
$odd
+=
$ncode[$x];
}
else
{
$even
+=
$ncode[$x];
}
}
$code.=(10
-
(($odd
*
3
+
$even)
%
10))
%
10;
/*
Create
the
bar
encoding
using
a
binary
string
*/
$bars=$ends;
$bars.=$Lencode[$code[0]];
for($x=1;$x<6;$x++)
{
$bars.=$Lencode[$code[$x]];
}
$bars.=$center;
for($x=6;$x<12;$x++)
{
$bars.=$Rencode[$code[$x]];
}
$bars.=$ends;
/*
Generate
the
Barcode
Image
*/
$img
=
ImageCreate($lw*75+30,$hi-3);
//
95
$fg
=
ImageColorAllocate($img,
0,
0,
0);
$bg
=
ImageColorAllocate($img,
255,
255,
255);
ImageFilledRectangle($img,
0,
0,
$lw*75+30,
$hi+30,
$bg);
$shift=10;
for
($x=0;$x<strlen($bars);$x++)
{
if
(($x<0)
||
($x>=45
&&
$x<46)
||
($x
>=85))
{
$sh=10;
}
else
{
$sh=0;
}
if
($bars[$x]
==
'1')
{
$color
=
$fg;
}
else
{
$color
=
$bg;
}
ImageFilledRectangle($img,
($x*$lw)+15,5,($x+1)*$lw+14,$hi+5+$sh,$color);
}
/*
Add
the
Human
Readable
Label
*/
ImageString($img,4,5,$hi-5,$code[0],$fg);
for
($x=0;$x<5;$x++)
{
ImageString($img,5,$lw*(13+$x*6)+15,$hi+5,$code[$x+1],$fg);
ImageString($img,5,$lw*(53+$x*6)+15,$hi+5,$code[$x+6],$fg);
}
ImageString($img,4,$lw*95-7,$hi,$code[11],$fg);
/*
Output
the
Header
and
Content.
*/
header("Content-Type:
image/png");
ImagePNG($img);
}
//}
echo
UPCAbarcode('201212070099');
如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
Ⅹ 如何使用Jgraph畫出如下雙坐標條形圖
tiao1=[562 548 224 545 41 445 745 512];
tiao2=[47 48 57 58 54 52 65 48];
t=0:7;
[ax,h1]=plotyy(t,tiao1,t,tiao2,@bar,@plot);
set(h1,'facecolor','g');
set(ax(1),'ytick',0:100:1000);
set(ax(2),'ylim',[0 100],'ytick',0:10:100);