- 论坛徽章:
- 0
|
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
- #!/usr/bin/perl -w
- use strict;
- use GD::Graph::lines;
- my $data = [
- ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
- [1, 2, 5, 6, 3, 1.5, 1, 3, 4],
- [ sort { $a <=> $b } (1, 2, 5, 6, 3, 1.5, 1, 3, 4) ]
- ];
- # create chart
- my $graph = GD::Graph::lines->new(400, 300);
- # Set the graph options.
- $graph->set(
- x_label => 'X Label',
- y_label => 'Y label',
- title => 'Demo GD::Graph::lines',
- y_max_value => 8,
- y_tick_number => 8,
- y_label_skip => 2,
- line_types =>[1, 2], # 1: solid, 2: dashed, 3: dotted, 4: dot-dashed.
- ) or die $graph->error;
- # print to browser
- my $format = $graph->export_format;
- print "Content-type: image/$format\n\n";
- binmode STDOUT;
- 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 编辑 ] |
|