JpGraph简介
JpGraph是开源的PHP统计图表生成库,基于PHP的GD2图形库构建,把生成统计图的相关 *** 作封装,隐藏了部分复杂的 *** 作,使在PHP页面上输出统计图表变得更加容易。JpGraph的官方网站为:http://jpgraph.net,开发者可以在上面免费下载最新版的JpGraph和阅读相关帮助文档或示例程序。
相关学习推荐:PHP编程从入门到精通
JpGraph的配置
(1)修改文件PHP.ini
在include_path中添加jpgraph的目录路径,并将jpgraph解压后的src目录名称更改为jpgraph。
(2)检查PHP是否支持GD库
在PHP.ini文件中找到语句;extension=PHP_gd2.dll。把上述语句前的;号去掉,即去掉注释。如果因为PHP版本不同而找不到此语句,则可直接添加extension=PHP_gd2.dll
(3)修改文件jpgraph_gb2312.PHP
找到函数:function gb2utf8($gb)
把函数修改为:
function gb2utf8($gb) { return $gb; }
即不使用gb2编码方式转utf8方式的那段代码。
折线图
<?PHP require_once ("jpgraph/jpgraph.PHP"); require_once ("jpgraph/jpgraph_line.PHP"); $data1 = array(523,634,371,278,685,587,490,256,398,545,367,577); //第一条曲线的数组 $graph = new Graph(500,300); $graph->SetScale("textlin"); $graph->SetShadow(); $graph->img->Setmargin(60,30,30,70); //设置图像边距 $graph->graph_theme = null; //设置主题为null,否则value->Show(); 无效 $lineplot1=new linePlot($data1); //创建设置两条曲线对象 $lineplot1->value->Setcolor("red"); $lineplot1->value->Show(); $graph->Add($lineplot1); //将曲线放置到图像上 $graph->Title->Set("CDN流量图"); //设置图像标题 $graph->xaxis->Title->Set("月份"); //设置坐标轴名称 $graph->yaxis->Title->Set("流 量(Gbits)"); $graph->Title->Setmargin(10); $graph->xaxis->Title->Setmargin(10); $graph->yaxis->Title->Setmargin(10); $graph->Title->SetFont(FF_SimsUN,FS_BolD); //设置字体 $graph->yaxis->Title->SetFont(FF_SimsUN,FS_BolD); $graph->xaxis->Title->SetFont(FF_SimsUN,FS_BolD); $graph->xaxis->SetTickLabels($gDateLocale->GetShortMonth()); $graph->stroke(); //输出图像 ?>
柱状图
<?PHP require_once ("jpgraph/jpgraph.PHP"); require_once ("jpgraph/jpgraph_bar.PHP"); $data = array(19,23,34,38,45,67,71,78,85,87,96,145); $ydata = array("一","二","三","四","五","六","七","八","九","十","十一","十二"); $graph = new Graph(500,300); //创建新的Graph对象 $graph->SetScale("textlin"); //刻度样式 $graph->SetShadow(); //设置阴影 $graph->img->Setmargin(40,30,40,50); //设置边距 $graph->graph_theme = null; //设置主题为null,否则value->Show(); 无效 $barplot = new barPlot($data); //创建barPlot对象 $barplot->SetFillcolor('blue'); //设置颜色 $barplot->value->Show(); //设置显示数字 $graph->Add($barplot); //将柱形图添加到图像中 $graph->Title->Set("CDN流量图"); $graph->xaxis->Title->Set("月份"); //设置标题和X-Y轴标题 $graph->yaxis->Title->Set("流 量(Mbits)"); $graph->Title->Setcolor("red"); $graph->Title->Setmargin(10); $graph->xaxis->Title->Setmargin(5); $graph->xaxis->SetTickLabels($ydata); $graph->Title->SetFont(FF_SimsUN,FS_BolD); //设置字体 $graph->yaxis->Title->SetFont(FF_SimsUN,FS_BolD); $graph->xaxis->Title->SetFont(FF_SimsUN,FS_BolD); $graph->xaxis->SetFont(FF_SimsUN,FS_BolD); $graph->stroke(); ?>
饼状图
<?PHP require_once ("jpgraph/jpgraph.PHP"); require_once ("jpgraph/jpgraph_pIE.PHP"); require_once ("jpgraph/jpgraph_pIE3d.PHP"); $data = array(19,23,34,38,45,67,71,78,85,87,90,96); $graph = new PIEGraph(550,500); $graph->SetShadow(); $graph->Title->Set("CDN流量比例"); $graph->Title->SetFont(FF_SimsUN,FS_BolD); $pIEplot = new PIEPlot3D($data); //创建PIEPlot3D对象 $pIEplot->SetCenter(0.4, 0.5); //设置饼图中心的位置 $pIEplot->SetLegends($gDateLocale->GetShortMonth()); //设置图例 $graph->Add($pIEplot); $graph->stroke(); ?>总结
以上是内存溢出为你收集整理的PHP jpgraph库的配置及生成多种统计图表全部内容,希望文章能够帮你解决PHP jpgraph库的配置及生成多种统计图表所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)