<?php
Class ImageReport{
var $X;//图片大小X轴
var $Y;//图片大小Y轴
var $R;//背影色R值
var $G;//...G.
var $B;//...B.
var $TRANSPARENT;//是否透明1或0
var $IMAGE;//图片对像
//-------------------
var $ARRAYSPLIT;//指定用于分隔数值的符号
var $ITEMARRAY;//数值
var $REPORTTYPE;//图表类型,1为竖柱形2为横柱形3为折线形
var $BORDER;//距离
//-------------------
var $FONTSIZE;//字体大小
var $FONTCOLOR;//字体颜色
//--------参数设置函数
function setImage($SizeX,$SizeY,$R,$G,$B,$Transparent){
$this->X=$SizeX;
$this->Y=$SizeY;
$this->R=$R;
$this->G=$G;
$this->B=$B;
$this->TRANSPARENT=$Transparent;
}
function setItem($ArraySplit,$ItemArray,$ReportType,$Border){
$this->ARRAYSPLIT=$ArraySplit;
$this->ITEMARRAY=$ItemArray;
$this->REPORTTYPE=$ReportType;
$this->BORDER=$Border;
}
function setFont($FontSize){
$this->FONTSIZE=$FontSize;
}
//----------------主体
function PrintReport(){
Header( "Content-type: image/gif");
//建立画布大小
$this->IMAGE=ImageCreate($this->X,$this->Y);
//设定画布背景色
$background=ImageColorAllocate($this->IMAGE,$this->R,$this->G,$this->B);
if($this->TRANSPARENT=="1"){
//背影透明
Imagecolortransparent($this->IMAGE,$background);
}else{
//如不要透明时可填充背景色
ImageFilledRectangle($this->IMAGE,0,0,$this->X,$this->Y,$background);
}
//参数字体文小及颜色
$this->FONTCOLOR=ImageColorAllocate($this->IMAGE,255-$this->R,255-$this->G,255-$this->B);
Switch ($this->REPORTTYPE){
case "0":
break;
case "1":
$this->imageColumnS();
break;
case "2":
$this->imageColumnH();
break;
case "3":
$this->imageLine();
break;
}
$this->printXY();
$this->printAll();
}
//-----------打印XY坐标轴
function printXY(){
//画XY坐标轴*/
$color=ImageColorAllocate($this->IMAGE,255-$this->R,255-$this->G,255-$this->B);
$xx=$this->X/10;
$yy=$this->Y-$this->Y/10;
ImageLine($this->IMAGE,$this->BORDER,$this->BORDER,$this->BORDER,$this->Y-$this->BORDER,$color);//X轴
ImageLine($this->IMAGE,$this->BORDER,$this->Y-$this->BORDER,$this->X-$this->BORDER,$this->Y-$this->BORDER,$color);//y轴
//Y轴上刻度
$rulerY=$this->Y-$this->BORDER;
while($rulerY>$this->BORDER*2){
$rulerY=$rulerY-$this->BORDER;
ImageLine($this->IMAGE,$this->BORDER,$rulerY,$this->BORDER-2,$rulerY,$color);
}
//X轴上刻度
$rulerX=$rulerX+$this->BORDER;
while($rulerX<($this->X-$this->BORDER*2)){
$rulerX=$rulerX+$this->BORDER;
//ImageLine($this->IMAGE,$this->BORDER,10,$this->BORDER+10,10,$color);
ImageLine($this->IMAGE,$rulerX,$this->Y-$this->BORDER,$rulerX,$this->Y-$this->BORDER+2,$color);
}
}
//--------------竖柱形图
function imageColumnS(){
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
$num=Count($item_array);
$item_max=0;
for ($i=0;$i<$num;$i++){
$item_max=Max($item_max,$item_array[$i]);
}
$xx=$this->BORDER*2;
//画柱形图
for ($i=0;$i<$num;$i++){
srand((double)microtime()*1000000);
if($this->R!=255 && $this->G!=255 && $this->B!=255){
$R=Rand($this->R,200);
$G=Rand($this->G,200);
$B=Rand($this->B,200);
}else{
$R=Rand(50,200);
$G=Rand(50,200);
$B=Rand(50,200);
}
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
//柱形高度
$height=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($item_array[$i]/$item_max);
ImageFilledRectangle($this->IMAGE,$xx,$height,$xx+$this->BORDER,$this->Y-$this->BORDER,$color);
ImageString($this->IMAGE,$this->FONTSIZE,$xx,$height-$this->BORDER,$item_array[$i],$this->FONTCOLOR);
//用于间隔
$xx=$xx+$this->BORDER*2;
}
}
//-----------横柱形图
function imageColumnH(){
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
$num=Count($item_array);
$item_max=0;
for ($i=0;$i<$num;$i++){
$item_max=Max($item_max,$item_array[$i]);
}
$yy=$this->Y-$this->BORDER*2;
//画柱形图
for ($i=0;$i<$num;$i++){
srand((double)microtime()*1000000);
if($this->R!=255 && $this->G!=255 && $this->B!=255){
$R=Rand($this->R,200);
$G=Rand($this->G,200);
$B=Rand($this->B,200);
}else{
$R=Rand(50,200);
$G=Rand(50,200);
$B=Rand(50,200);
}
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
//柱形长度
$leight=($this->X-$this->BORDER*2)*($item_array[$i]/$item_max);
ImageFilledRectangle($this->IMAGE,$this->BORDER,$yy-$this->BORDER,$leight,$yy,$color);
ImageString($this->IMAGE,$this->FONTSIZE,$leight+2,$yy-$this->BORDER,$item_array[$i],$this->FONTCOLOR);
//用于间隔
$yy=$yy-$this->BORDER*2;
}
}
//--------------折线图
function imageLine(){
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
$num=Count($item_array);
$item_max=0;
for ($i=0;$i<$num;$i++){
$item_max=Max($item_max,$item_array[$i]);
}
//$xx=$this->BORDER;
//画柱形图
for ($i=0;$i<$num;$i++){
srand((double)microtime()*1000000);
if($this->R!=255 && $this->G!=255 && $this->B!=255){
$R=Rand($this->R,200);
$G=Rand($this->G,200);
$B=Rand($this->B,200);
}else{
$R=Rand(50,200);
$G=Rand(50,200);
$B=Rand(50,200);
}
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
//柱形高度
$height_now=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($item_array[$i]/$item_max);
if($i!="0"){
ImageLine($this->IMAGE,$xx,$height_next,$xx+$this->BORDER,$height_now,$color);
}
ImageString($this->IMAGE,$this->FONTSIZE,$xx+$this->BORDER,$height_now-$this->BORDER/2,$item_array[$i],$this->FONTCOLOR);
$height_next=$height_now;
//用于间隔
$xx=$xx+$this->BORDER;
}
}
//--------------完成打印图形http://knowsky.com
function printAll(){
ImageGIF($this->IMAGE);
ImageDestroy($this->IMAGE);
}
//--------------调试
function debug(){
echo "X:".$this->X."
Y:".$this->Y;
echo "
BORDER:".$this->BORDER;
$item_array=split($this->ARRAYSPLIT,$this->ITEMARRAY);
$num=Count($item_array);
echo "
数值个数:".$num."
数值:";
for ($i=0;$i<$num;$i++){
echo "
".$item_array[$i];
}
}
}
$report=new ImageReport;
$report->setImage(600,300,255,255,255,1);//参数(长,宽,背影色R,G,B,是否透明1或0)
$temparray="50,25,100,250,180,200,150,220,200,150,50,25,100,250,180,200,150,220,200,150";//数值,用指定符号隔开
$report->setItem(',',$temparray,3,20);//参数(分隔数值的指定符号,数值变量,样式1为竖柱图2为横柱图3为折线图,距离)
$report->setFont(1);//字体大小1-10
$report->PrintReport();
//$report->debug();//调式之用
?>
Class ImageReport{
var $X;//图片大小X轴
var $Y;//图片大小Y轴
var $R;//背影色R值
var $G;//...G.
var $B;//...B.
var $TRANSPARENT;//是否透明1或0
var $IMAGE;//图片对像
//-------------------
var $ARRAYSPLIT;//指定用于分隔数值的符号
var $ITEMARRAY;//数值
var $REPORTTYPE;//图表类型,1为竖柱形2为横柱形3为折线形
var $BORDER;//距离
//-------------------
var $FONTSIZE;//字体大小
var $FONTCOLOR;//字体颜色
//--------参数设置函数
function setImage($SizeX,$SizeY,$R,$G,$B,$Transparent){
$this->X=$SizeX;
$this->Y=$SizeY;
$this->R=$R;
$this->G=$G;
$this->B=$B;
$this->TRANSPARENT=$Transparent;
}
function setItem($ArraySplit,$ItemArray,$ReportType,$Border){
$this->ARRAYSPLIT=$ArraySplit;
$this->ITEMARRAY=$ItemArray;
$this->REPORTTYPE=$ReportType;
$this->BORDER=$Border;
}
function setFont($FontSize){
$this->FONTSIZE=$FontSize;
}
//----------------主体
function PrintReport(){
Header( "Content-type: image/gif");
//建立画布大小
$this->IMAGE=ImageCreate($this->X,$this->Y);
//设定画布背景色
$background=ImageColorAllocate($this->IMAGE,$this->R,$this->G,$this->B);
if($this->TRANSPARENT=="1"){
//背影透明
Imagecolortransparent($this->IMAGE,$background);
}else{
//如不要透明时可填充背景色
ImageFilledRectangle($this->IMAGE,0,0,$this->X,$this->Y,$background);
}
//参数字体文小及颜色
$this->FONTCOLOR=ImageColorAllocate($this->IMAGE,255-$this->R,255-$this->G,255-$this->B);
Switch ($this->REPORTTYPE){
case "0":
break;
case "1":
$this->imageColumnS();
break;
case "2":
$this->imageColumnH();
break;
case "3":
$this->imageLine();
break;
}
$this->printXY();
$this->printAll();
}
//-----------打印XY坐标轴
function printXY(){
//画XY坐标轴*/
$color=ImageColorAllocate($this->IMAGE,255-$this->R,255-$this->G,255-$this->B);
$xx=$this->X/10;
$yy=$this->Y-$this->Y/10;
ImageLine($this->IMAGE,$this->BORDER,$this->BORDER,$this->BORDER,$this->Y-$this->BORDER,$color);//X轴
ImageLine($this->IMAGE,$this->BORDER,$this->Y-$this->BORDER,$this->X-$this->BORDER,$this->Y-$this->BORDER,$color);//y轴
//Y轴上刻度
$rulerY=$this->Y-$this->BORDER;
while($rulerY>$this->BORDER*2){
$rulerY=$rulerY-$this->BORDER;
ImageLine($this->IMAGE,$this->BORDER,$rulerY,$this->BORDER-2,$rulerY,$color);
}
//X轴上刻度
$rulerX=$rulerX+$this->BORDER;
while($rulerX<($this->X-$this->BORDER*2)){
$rulerX=$rulerX+$this->BORDER;
//ImageLine($this->IMAGE,$this->BORDER,10,$this->BORDER+10,10,$color);
ImageLine($this->IMAGE,$rulerX,$this->Y-$this->BORDER,$rulerX,$this->Y-$this->BORDER+2,$color);
}
}
//--------------竖柱形图
function imageColumnS(){
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
$num=Count($item_array);
$item_max=0;
for ($i=0;$i<$num;$i++){
$item_max=Max($item_max,$item_array[$i]);
}
$xx=$this->BORDER*2;
//画柱形图
for ($i=0;$i<$num;$i++){
srand((double)microtime()*1000000);
if($this->R!=255 && $this->G!=255 && $this->B!=255){
$R=Rand($this->R,200);
$G=Rand($this->G,200);
$B=Rand($this->B,200);
}else{
$R=Rand(50,200);
$G=Rand(50,200);
$B=Rand(50,200);
}
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
//柱形高度
$height=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($item_array[$i]/$item_max);
ImageFilledRectangle($this->IMAGE,$xx,$height,$xx+$this->BORDER,$this->Y-$this->BORDER,$color);
ImageString($this->IMAGE,$this->FONTSIZE,$xx,$height-$this->BORDER,$item_array[$i],$this->FONTCOLOR);
//用于间隔
$xx=$xx+$this->BORDER*2;
}
}
//-----------横柱形图
function imageColumnH(){
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
$num=Count($item_array);
$item_max=0;
for ($i=0;$i<$num;$i++){
$item_max=Max($item_max,$item_array[$i]);
}
$yy=$this->Y-$this->BORDER*2;
//画柱形图
for ($i=0;$i<$num;$i++){
srand((double)microtime()*1000000);
if($this->R!=255 && $this->G!=255 && $this->B!=255){
$R=Rand($this->R,200);
$G=Rand($this->G,200);
$B=Rand($this->B,200);
}else{
$R=Rand(50,200);
$G=Rand(50,200);
$B=Rand(50,200);
}
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
//柱形长度
$leight=($this->X-$this->BORDER*2)*($item_array[$i]/$item_max);
ImageFilledRectangle($this->IMAGE,$this->BORDER,$yy-$this->BORDER,$leight,$yy,$color);
ImageString($this->IMAGE,$this->FONTSIZE,$leight+2,$yy-$this->BORDER,$item_array[$i],$this->FONTCOLOR);
//用于间隔
$yy=$yy-$this->BORDER*2;
}
}
//--------------折线图
function imageLine(){
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
$num=Count($item_array);
$item_max=0;
for ($i=0;$i<$num;$i++){
$item_max=Max($item_max,$item_array[$i]);
}
//$xx=$this->BORDER;
//画柱形图
for ($i=0;$i<$num;$i++){
srand((double)microtime()*1000000);
if($this->R!=255 && $this->G!=255 && $this->B!=255){
$R=Rand($this->R,200);
$G=Rand($this->G,200);
$B=Rand($this->B,200);
}else{
$R=Rand(50,200);
$G=Rand(50,200);
$B=Rand(50,200);
}
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
//柱形高度
$height_now=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($item_array[$i]/$item_max);
if($i!="0"){
ImageLine($this->IMAGE,$xx,$height_next,$xx+$this->BORDER,$height_now,$color);
}
ImageString($this->IMAGE,$this->FONTSIZE,$xx+$this->BORDER,$height_now-$this->BORDER/2,$item_array[$i],$this->FONTCOLOR);
$height_next=$height_now;
//用于间隔
$xx=$xx+$this->BORDER;
}
}
//--------------完成打印图形http://knowsky.com
function printAll(){
ImageGIF($this->IMAGE);
ImageDestroy($this->IMAGE);
}
//--------------调试
function debug(){
echo "X:".$this->X."
Y:".$this->Y;
echo "
BORDER:".$this->BORDER;
$item_array=split($this->ARRAYSPLIT,$this->ITEMARRAY);
$num=Count($item_array);
echo "
数值个数:".$num."
数值:";
for ($i=0;$i<$num;$i++){
echo "
".$item_array[$i];
}
}
}
$report=new ImageReport;
$report->setImage(600,300,255,255,255,1);//参数(长,宽,背影色R,G,B,是否透明1或0)
$temparray="50,25,100,250,180,200,150,220,200,150,50,25,100,250,180,200,150,220,200,150";//数值,用指定符号隔开
$report->setItem(',',$temparray,3,20);//参数(分隔数值的指定符号,数值变量,样式1为竖柱图2为横柱图3为折线图,距离)
$report->setFont(1);//字体大小1-10
$report->PrintReport();
//$report->debug();//调式之用
?>
标签:
php下实现折线图效果的代码
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“php下实现折线图效果的代码”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。