lorenzob has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks,
i'm trying to draw a graph using GD::Graph and more or less i got it using piece of code below.
As you can see data of my array are hardcoded in the script, while i would like to read data from external input file and then draw my graph.
Many thanks in advance to anyone that will help me.
Hers's my script:
#!/usr/bin/perl use strict; use GD::Graph::bars3d; use Date::Calc qw(:all); use GD::Graph::Data; my ($d,$m,$y) = (localtime)[3,4,5]; my $mdy = sprintf '%02d-%02d-%02d', $d, $m+1, $y+1900; my $title="IPTV - Video Server Bandwidth Report del "."$mdy"; my @data = ( ["00:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00","08 +:00","09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00", +"17:00","18:00","19:00","20:00","21:00","22:00","23:00"], [2585.54, 2095.44, 1748.02, 1454.55, 1290.86, 1235.33, 1151.04, 1160 +.86, 1191.82, 1343, 1514.33, 1693.67, 1773.7, 1897.82, 2733.04, 3257. +12, 3375.69, 2949.53, 2573.52, 2139.65, 1697.83, 1989.94, 2746.92, 29 +98.7], ); my $graph = new GD::Graph::bars3d( 1000, 500 ); $graph->set( x_label => 'Intervallo Orario', y_label => 'Traffico in Mbit/s', title => $title, x_labels_vertical => 1, x_label_position => 1/2, y_tick_number => 10, y_label_skip => 1, x_label_skip => 1, x_all_ticks => 1, x_labels_vertical => 1, box_axis => 0, y_long_ticks => 1, dclrs => [ qw(green) ], borderclrs => [ qw(black) ], #white,lgray,gray,dgray,black,lblue,blue,dblue,gold,lyellow,yellow,dye +llow,lgreen,green,dgreen,lred,red,dred,lpurple,purple,dpurple,lorange +,orange,pink,dpink,marine,cyan,lbrown,dbrown show_values => 1, values_vertical => 1, values_space => 15, bar_spacing => 10, ); my $gd = $graph->set_values_font(GD::gdGiantFont); my $gd = $graph->set_title_font(GD::gdGiantFont); my $gd = $graph->set_x_label_font(GD::gdGiantFont); my $gd = $graph->set_y_label_font(GD::gdGiantFont); my $gd = $graph->set_x_axis_font(GD::gdGiantFont); my $gd = $graph->set_y_axis_font(GD::gdGiantFont); my $gd = $graph->plot( \@data ); open(IMG, '>file.jpeg') or die $!; binmode IMG; print IMG $gd->jpeg; close IMG;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: GD::Graph input file
by toolic (Bishop) on Jul 18, 2011 at 19:01 UTC | |
by lorenzob (Acolyte) on Jul 18, 2011 at 19:17 UTC | |
|
Re: GD::Graph input file
by BrowserUk (Patriarch) on Jul 18, 2011 at 19:22 UTC | |
by lorenzob (Acolyte) on Jul 19, 2011 at 13:36 UTC |