免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2299 | 回复: 1
打印 上一主题 下一主题

[TIPS][WEB][GRAPHIC] use GD::Graph to draw a graphic chart [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-07-27 19:34 |只看该作者 |倒序浏览
This demo how to use CPAN module GD::Graph
Step by step:
1. install CPAN module:
cpan>install GD::Graph
2. read doc with perldoc
>perldoc GD::Graph
3.try this demo:
filename: chart_demo.cgi

  1. #!/usr/bin/perl -w
  2. use strict;
  3. use GD::Graph::lines;

  4. my  $data = [
  5.     ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
  6.     [1, 2, 5, 6, 3, 1.5, 1, 3, 4],
  7.     [ sort { $a <=> $b } (1, 2, 5, 6, 3, 1.5, 1, 3, 4) ]
  8. ];
  9. # create chart
  10. my $graph = GD::Graph::lines->new(400, 300);
  11. # Set the graph options.
  12. $graph->set(
  13.     x_label => 'X Label',
  14.     y_label => 'Y label',
  15.     title => 'Demo GD::Graph::lines',
  16.     y_max_value => 8,
  17.     y_tick_number => 8,
  18.     y_label_skip  => 2,
  19.     line_types =>[1, 2], # 1: solid, 2: dashed, 3: dotted, 4: dot-dashed.
  20. ) or die $graph->error;

  21. # print to browser
  22. my $format = $graph->export_format;
  23. print "Content-type: image/$format\n\n";
  24. binmode STDOUT;
  25. print $graph->plot($data)->$format;
复制代码

4. save this file chart_demo.cgi under the path of YOUR_WEBSERVER_CGI_BIN/
and  chmod +x chart_demo.cgi.
5. point your web browser to http://your.web.host/cgi-bin/chart.demo.cgi
6. you will see the chart.

Just 4 Fun,
    ulmer

[ 本帖最后由 ulmer 于 2006-7-28 21:10 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2006-07-28 00:14 |只看该作者
preserving!
thanks.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP