PHP使用JPGRAPH制作圆柱图的方法详解(2)
这个时候,我们已经完成了我们绘制图形所需要的数据了,接下来就是创建圆柱和调整它的颜色了
所要做的代码如下:
$graph = new Graph (500,400);//创建一个新的Graph对象,其宽和高分别为500,300 $graph -> SetScale("textlin");//设置其刻印样式 $graph -> SetShadow();//设置其阴影样式 $graph -> img -> SetMargin(40,30,40,50);//设置其上间距40,右间距30,下间距40,左间距50 $graph -> graph_theme = null;//设置他的主题为空,使得下面的元素可实现 $bplot = new BarPlot ($date);//创建BarPlot对象 $bplot -> SetColor("pink");//设置BarPlot的颜色 $bplot -> value -> Show("");//显示他的值 $graph ->Add($bplot);//把他的值放入$graph里 $graph -> title -> Set(iconv("utf-8","gb2312//IGNORE","年度收支表"));//设置标题名字并进行转换 $graph -> xaxis -> title -> Set(iconv("utf-8","gb2312//IGNORE","月份"));//同上,设置x轴标题 $graph -> yaxis -> title -> Set(iconv("utf-8","gb2312//IGNORE","总金额(兆美元)"));//同上,设置y轴标题 $graph -> title -> SetColor("red");//设置标题颜色 $graph -> title -> SetMargin(10);//设置标题间距 $graph -> xaxis -> title -> SetMargin(1);//设置x轴标题间距 $graph -> xaxis ->SetTickLabels($xdate);//接收xdate数组里的元素 $graph -> title -> SetFont(FF_SIMSUN,FS_BOLD);//设置字体样式 $graph -> xaxis -> title ->SetFont(FF_SIMSUN,FS_BOLD); $graph -> yaxis -> title ->SetFont(FF_SIMSUN,FS_BOLD); $graph -> xaxis -> SetFont(FF_SIMSUN,FS_BOLD);//设置x轴里所有的字体样式 $graph -> Stroke();//输出
到这里,我们的圆柱就已经完成了,完整的代码如下:
<?php require_once ("jpgraph/src/jpgraph.php"); require_once ("jpgraph/src/jpgraph_bar.php"); $date = array(19,23,34,38,45,67,71,78,85,87,90,96); $xdate = array("1","2","3","4","5","6","7","8","9","10","11","12"); $graph = new Graph (500,400); $graph->SetScale("textlin"); $graph->SetShadow(); $graph->img->SetMargin(40,30,40,50); $graph->graph_theme = null; $barplot = new BarPlot($date); $barplot->SetFillColor("pink"); $barplot->value->Show(); $graph->Add($barplot); $graph->title->Set(iconv("utf-8","GB2312//IGNORE","年度收支表")); $graph->xaxis->title->Set(iconv("utf-8","GB2312//IGNORE","月份")); $graph->yaxis->title->Set(iconv("utf-8","GB2312//IGNORE","总金额(兆美元)")); $graph->title->SetColor("red"); $graph->title->SetMargin(10); $graph->xaxis->title->SetMargin(1); $graph->xaxis->SetTickLabels($xdate); $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(); ?>
内容版权声明:除非注明,否则皆为本站原创文章。