GDGraph-1.44 版本 GD画图总结

                                       GDGraph-1.44 版本 GD画图总结
 
注: GDGraph-1.44英文文档及相应的perl GD包可以去http://cpan.org下载,至于包下载后如何安装则可以参考前面的文章《Windows 下如何手工安装perl模块包》

1.GD::Graph包可以创建的统计图最常见的有以下几种
 1)GD::Graph::lines  #创建折线图
 2)GD::Graph::bars and GD::Graph::bars #水平柱状图或垂直柱状图
 3)GD::Graph::points  #点状图
 4)GD::Graph::linespoints #折线图,但是数据部分用点显示
 5)GD::Graph::pie #饼图
2. 常见的几种图的code源码perl-CGI
 2.1 饼状图
 use   strict;  
   use   CGI;  
   use   GD::Graph::pie
 use   constant   TITLE   =>"Pie Chart"; #图标的标题
   my  $q =new   CGI;  
 print   $q->header( -type => "image/png",-expires   => "-1d");
 my   $graph_pie = new GD::Graph::pie(  200,  200   );    
 my   @data     =  (  
          [   qw( blocker  naormal trivial  Enhancement )   ],
          [           13,     24,     23,     19 ],        
  );  
 $graph_pie->set(
 '3d' => 0,              #是三维饼图还是二维饼图
 dclrs=>[qw(green marine pink cyan)], #饼图各种分类的颜色
 legend_placement    => 'TT',      # 图例位置
 legend_spacing   => 10,           #图例空间
 pie_height    =>   20,
 start_angle   =>   235,        #开始分图的角度
 legend_spacing   => 10,
 l_margin    => 20 ,       # 左边距
 b_margin     => 20,       # 下边距
 r_margin    => 20,        # 右边距
 t_margin    => 20,        # 上边距
 
  );
 $graph_pie->set_value_font("c:/WINDOWS/fonts/arial.ttf",10); #设置数值的字体
 $graph_pie->set_legend( qw( blocker  naormal trivial  Enhancement ));
 #设置图例,如果需要显示百分比的则需要自己组串,支持带入变量
 $graph_pie->set_legend_font("c:/WINDOWS/fonts/arial.ttf",10);#设置图例的字体

 my $gd_image   =$graph_pie->plot( /@data)||die $graph_pie->error;#画图
 #下面代码是将生成的图片保存到本地
 open ($FH ,"> c:/bugzilla/bug_severity_pie.png")||die "open failed!";
 binmode $FH;
 print $FH $gd_image->png ; 
 close $FH;
 2.2 折线图
 use   strict;  
  use   CGI;  
  use   GD::Graph::line;  
  my  $q =new   CGI;  
 print $q->header( -type => "image/png",-expires   => "-1d");
 $graph = new GD::Graph::lines( 400,300);
 $graph->set_x_label_font("c:/WINDOWS/fonts/arial.ttf",10);#设置字体
 $graph->set_y_label_font("c:/WINDOWS/fonts/arial.ttf",10);
 $graph->set_x_axis_font("c:/WINDOWS/fonts/arial.ttf",8 );
 $graph->set_y_axis_font("c:/WINDOWS/fonts/arial.ttf",10);
 $graph->set_legend_font("c:/WINDOWS/fonts/arial.ttf",10);
 $graph->set_legend("bugs");

 $graph->set(
 x_label=> 'MM-DD',  #横坐标
 y_label=>'Bugs',    #纵坐标
 x_label_skip=>1,    #刻度显示
 x_label_position=>1,#横坐标显示的位置
 y_label_position=>1,#纵坐标显示的位置
 borderclrs => "purple",
 #bgclr=>'lyellow',
 dclrs => [ qw(yellow) ],#折线的颜色
 t_margin=>1 ,           #边界
 #transparent => 0,      #背景是否透明
 bar_spacing       => 6,
 shadow_depth      => 2,
 #shadowclr         => 'lblue',
 show_values       => 5,
 legend_placement  => "RT",
 y_max_value  => $maxbugs,
 y_tick_number => 2,
 y_label_skip  => 1,
 box_axis=>1,         #
 x_labels_vertical=>1,#如果横坐标的刻度说明比较长的话就需要用到该参数
 labelclr=>'lblue',    #坐标的颜色
 axislabelclr=>'black', #轴的颜色
 valuesclr=>'black',    # 值的颜色
 l_margin    => 10 ,       # 各个边距
 b_margin        => 10,
 r_margin       => 10,
 t_margin       => 10, 
) || die $graph->error;
 
其他就不举例了,总之,除了饼图有点区别外,其他的统计图设置都差不多,没有太大的区别!具体情况可以参靠该包的详细说明文档,
此外1.44包自身还带有很多例子,适合第一次使用该包的同学学习。

 

  • 0
    点赞
  • 1
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aotup

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值