Jpgraph是开源的PHP统计图表天生库,基于PHP的GD2图形库构建,把天生统计图的干系操作封装,隐蔽了部分繁芜的操作,使在PHP页面上输出统计图表变得更加随意马虎。JpGraph的官方网站为:http://jpgraph.net,开拓者可以在上面免费下载最新版的JpGraph和阅读干系帮助文档或示例程序。
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办法的那段代码。
折线图
<?phprequire_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(); //输出图像?>
柱状图
<?phprequire_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();?>
效果如图:
饼状图
<?phprequire_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的道路上,看看口试根本题吧
Redis干系口试题