Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hello fellow Monks!
I have made this script for creating histogram plots:
sub save_chart { my $chart = shift or die "Need a chart!"; my $name = shift or die "Need a name!"; local(*OUT); my $ext = 'png'; open(OUT, ">$name.$ext") or die "Cannot open $name.$ext for write: $!"; binmode OUT; print OUT $chart->gd->$ext(); close OUT; } use GD::Graph::bars; use GD::Graph::hbars; use GD::Graph::colour; my @data = ( ["name1", "name2", "name3","name4"], [23, 26, 53, 27], [77, 74, 47, 73] ); my @names = qw/sample15 sample15-h/; my $font_dir = '/usr/share/fonts/truetype'; my $font_file = "$font_dir/freefont/FreeSans.ttf"; for my $my_graph (GD::Graph::bars->new, GD::Graph::hbars->new(700,500) +) { my $name = shift @names; print STDERR "Creating image\n"; $my_graph->set( bgclr => 'white', box_axis => 0, y_max_value => 100, dclrs => ['#ff782a', '#6daa3a'], title => 'MY_TITLE', bar_width => 10, bar_spacing => 4, y_tick_number => 2, cumulate => 2, borderclrs => $my_graph->{dclrs}, bar_spacing => 4, transparent => 0, x_label_position => 0.5, tick_length => -4, axis_space => 6, x_ticks => 0, bar_spacing => 1, bargroup_spacing => 20, fgclr => '#bbbbbb', axislabelclr => '#333333', labelclr => '#333333', textclr => '#333333', legendclr => '#333333', legend_placement => 'DC', legend_marker_width => 12, legend_marker_height => 12, legend_spacing => 6, long_ticks => 0, borderclrs => [undef] ); $my_graph->set_title_font($font_file, 16); $my_graph->set_x_label_font($font_file, 16); $my_graph->set_y_label_font($font_file, 16); $my_graph->set_x_axis_font($font_file, 11); $my_graph->set_y_axis_font($font_file, 11); $my_graph->set_legend_font($font_file, 11); $my_graph->set_legend(qw(%leg1 %leg2)); $my_graph->plot(\@data); save_chart($my_graph, $name); }

Can you please tell me how I can pass the arrays in @data instead of hard-coding them inside the script? Because I want to make the script "universal"... I mean, if I have 3 arrays, namely @array_names, @array_numbers1 and @array_numbers2, how do I pass their values into the array @data?
Thank you!

In reply to How to pass arrays into this program? by Anonymous Monk

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-23 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found