导航:首页 > 编程语言 > php条形图

php条形图

发布时间:2022-12-27 19:07:51

Ⅰ 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);

阅读全文

与php条形图相关的资料

热点内容
dvd光盘存储汉子算法 浏览:757
苹果邮件无法连接服务器地址 浏览:962
phpffmpeg转码 浏览:671
长沙好玩的解压项目 浏览:144
专属学情分析报告是什么app 浏览:564
php工程部署 浏览:833
android全屏透明 浏览:736
阿里云服务器已开通怎么办 浏览:803
光遇为什么登录时服务器已满 浏览:302
PDF分析 浏览:484
h3c光纤全工半全工设置命令 浏览:143
公司法pdf下载 浏览:381
linuxmarkdown 浏览:350
华为手机怎么多选文件夹 浏览:683
如何取消命令方块指令 浏览:349
风翼app为什么进不去了 浏览:778
im4java压缩图片 浏览:362
数据查询网站源码 浏览:150
伊克塞尔文档怎么进行加密 浏览:892
app转账是什么 浏览:163