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;

In reply to GD::Graph input file by lorenzob

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.