欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php图形jpgraph操作实例分析

程序员文章站 2024-03-13 18:50:09
本文实例讲述了php图形jpgraph操作。分享给大家供大家参考,具体如下:

本文实例讲述了php图形jpgraph操作。分享给大家供大家参考,具体如下:

<?php
include ("src/jpgraph.php");
include("src/jpgraph_bar.php");
include ("src/jpgraph_line.php");
//设置显示的数据数组;
//调用类库
//设置图像的大小
$graph = new graph(400,200,"auto");
$graph->setscale("textlin");
//设置图形的边距
$graph->img->setmargin(40,180,40,40);
//设置图形的背景图片,填充方式有:bgimg_fillplot, bgimg_fillframe, bgimg_copy
$graph->setbackgroundimage("abc.jpg",bgimg_fillplot);
$graph->img->setangle(45); //设置图形在图像中的角度
//设置背景图片的对比度,must be between -1 <= x <= 1, (0,0)=original image
$graph->adjbackgroundimage(0,0);
//设置投影;
//$graph->setshadow();
//设置标题
$graph->title->set("test image");
//设置标题字体样式
$graph->title->setfont(ff_font1,fs_bold);
//设置标题的边距
$graph->title->setmargin(3);
//设置图列的位置
$graph->legend->pos(0.05,0.5,"right","center");
//设置图列的投影,颜色
$graph->legend->setshadow('darkgray@0.1');
$graph->legend->setfillcolor('lightblue@0.3');
//设置x轴的标记
$graph->xaxis->setticklabels($label_x);
//设置x轴的显示值的角度;
$graph->xaxis->setlabelangle(30);
//设置x轴标题和字体颜色
$graph->xaxis->title->set('year 2006');
$graph->xaxis->title->setfont(ff_font1,fs_bold);
$graph->xaxis->title->setcolor('white');
//设置x轴的字体和颜色
$graph->xaxis->setfont(ff_font1,fs_bold);
$graph->xaxis->setcolor('yellow');
//设置y轴的字体和颜色
$graph->yaxis->setfont(ff_font1,fs_bold);
$graph->yaxis->setcolor('yellow');
//设置是否显示格子。默认为显示;
//$graph->ygrid->show(false);
//设置格子的颜色和粗细。值越小,格子越粗。
$graph->ygrid->setcolor('yellow@0.5');
//设置y轴更优美一些
$graph->yaxis->scale->setgrace(20);
//设置图列的数据
$bplot1 = new barplot($datay1);
$bplot2 = new barplot($datay2);
//设置图列的填充颜色
$bplot1->setfillcolor('orange@0.4');
$bplot2->setfillcolor('brown@0.4');
//设置值的格式
$bplot1->value->setformat('%d');
//设置图列标签
$bplot1->setlegend('label 1');
$bplot2->setlegend('label 2');
//设置图列在图中的阴影
$bplot1->setshadow('black@0.4');
$bplot2->setshadow('black@0.4');
//生成图列
$gbarplot = new groupbarplot(array($bplot1,$bplot2));
$gbarplot->setwidth(0.9);
$graph->add($gbarplot);
//生成图形
$graph->stroke();
//上面所说的时在生成柱形图,当生成线性图时用下面的方法
$p1 = new lineplot($datay);
$p1->mark->settype(mark_filledcircle);
$p1->mark->setfillcolor("red");
$p1->mark->setwidth(4);
$p1->setcolor("blue");
$p1->setcenter();
$p1->setlegend("triumph tiger -98");
$graph->add($p1);
$p2 = new lineplot($data2y);
$p2->mark->settype(mark_star);
$p2->mark->setfillcolor("red");
$p2->mark->setwidth(4);
$p2->setcolor("red");
$p2->setcenter();
$p2->setlegend("new tiger -99");
$graph->add($p2);
// style can also be specified as setstyle([1|2|3|4]) or
// setstyle("solid"|"dotted"|"dashed"|"lobgdashed")
$lineplot->setstyle("dashed");//设置线的样式
$graph->yaxis->scale->setgrace(20); //设置y轴更优美一些
?>

2.柱形图和饼状图举例

if($tag == 1)
{
$graph = new graph(600,400,"auto");
$graph->setscale("textlin");
$graph->setmargincolor('lightblue');
$graph->setshadow();
$graph->setmargin(30,100,30,60);
//设置标题;
$graph->title->set("文章分类汇总");
$graph->title->setmargin(3);
$graph->title->setfont(ff_simsun,fs_bold);
$graph->title->setcolor('black@0.5');
$graph->yaxis->title->setfont(ff_simsun,fs_bold);
$graph->xaxis->title->setfont(ff_simsun,fs_bold);
$graph->xaxis->setfont(ff_simsun,fs_normal);
$graph->xaxis->setcolor('darkblue','black');
$graph->xaxis->setticklabels($name);
$graph->xaxis->setlabelangle(30);
$bplot = new barplot($article_num);
$bplot->setfillcolor("orange");
$bplot->value->setformat('%d');
$bplot->setshadow('darkgray');
$bplot->value->show();
$graph->legend->setfont(ff_simsun,fs_bold);
$bplot->setlegend("文章数");
$graph->add($bplot);
$graph->stroke();
}
else
{
$graph1 = new piegraph(600,400,"auto");
$graph1->setscale("textlin");
$graph1->setshadow();
$graph1->title->setfont(ff_simsun,fs_bold);
$graph1->title->set("用户文章饼形图");
$graph1->setmargin(30,100,30,60);
$p1 = new pieplot3d($article_num);
$p1->setangle(80);
$p1->setsize(0.5);
$p1->setshadow();
$p1->explodeslice(2);
$p1->setcenter(0.4);
$graph1->legend->setfont(ff_simsun,fs_normal);
$graph1->legend->setshadow();
$p1->setlegends($name);
$graph1->add($p1);
$graph1->stroke();
}
//生成本地图片
$graph->stroke("路径/文件名.png");

更多关于php相关内容感兴趣的读者可查看本站专题:《php图形与图片操作技巧汇总》、《php基本语法入门教程》、《php面向对象程序设计入门教程》、《php网络编程技巧总结》、《php数组(array)操作技巧大全》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家php程序设计有所帮助。