当前位置: 首页 > 文章教程  > 计算机与互联网 > 网络编程

12.4实战演练——制作3D饼形统计图

9/17/2020 9:40:31 PM 人评论

12.4实战演练——制作3D饼形统计图

12.4 实战演练——制作3D饼形统计图

下面就通过3D饼形图例程的介绍,来了解JpGraph类的使用方法和技巧,具体步骤如下。

01 在phpimage文件夹下找到安装过的jpgraph类库文件夹,在其下的src文件夹下找到Examples文件夹。找到pie3dex3.php文件,将其复制到phpimage文件夹下,打开代码如下。

  <?php
  require_once ('jpgraph/ jpgraph.php');
  require_once ('jpgraph/jpgraph_pie.php');
  require_once ('jpgraph/jpgraph_pie3d.php');
  $data = array(20,27,45,75,90);
  $graph = new PieGraph(450,200);
  $graph->SetShadow();
  $graph->title->Set("Example 1 3D Pie plot");
  $graph->title->SetFont(FF_VERDANA,FS_BOLD,18);
  $graph->title->SetColor("darkblue");
  $graph->legend->Pos(0.5,0.8);
  $p1 = new PiePlot3d($data);
  $p1->SetTheme("sand");
  $p1->SetCenter(0.4);
  $p1->SetAngle(30);
  $p1->value->SetFont(FF_ARIAL,FS_NORMAL,12);
  $p1->SetLegends(array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct"));
  $graph->Add($p1);
  $graph->Stroke();
  ?>

02 修改require_once ('jpgraph/jpgraph.php');为require_once ('jpgraph/src/jpgraph.php');。修改require_once ('jpgraph/jpgraph_pie.php');为require_once ('jpgraph/src/ jpgraph_pie.php ');。修改require_once ('jpgraph/jpgraph_pie3d.php');为require_once ('jpgraph/src/ jpgraph_pie3d.php ');。以载入本机JpGraph类库。

运行pie3dex3.php,结果如图12-9所示。

image

图12-9 pie3dex3.php页面效果

【案例分析】

(1)require_once ('jpgraph/src/jpgraph.php');、require_once ('jpgraph/jpgraph_pie. php');和require_once ('jpgraph/jpgraph_pie3d.php');语句加载了JpGraph基本类库jpgraph.php、饼形图类库jpgraph_ pie.php和3d饼形图类库jpgraph_ pie3d.php。

(2)$data定义了要表现的数据。

(3)$graph = new PieGraph(450,200);生成图形。$graph->SetShadow();设定阴影。

(4)$graph->title->Set("Example 1 3D Pie plot");设定标题。$graph->title->SetFont (FF_VERDANA,FS_BOLD,18);设定字体和字体大小。$graph->title->SetColor("darkblue");设定颜色。$graph->legend->Pos(0.5,0.8);设定图例在整个图形中的位置。

(5)$p1 = new PiePlot3d($data);生成饼形图。$p1->SetTheme("sand");设置饼形图模板。$p1->SetCenter(0.4);设置饼形图的中心。$p1->SetAngle(30);设置饼形图角度。$p1->value-> SetFont(FF_ARIAL,FS_NORMAL,12);设置字体。$p1->SetLegends(array("Jan",….,"Oct"));设置图例文字信息。

(6)$graph->Add($p1);向整个图形添加饼形图。$graph->Stroke();把此图传递到浏览器显示。

相关教程

共有条评论 网友评论

验证码: 看不清楚?