sidsinha has asked for the wisdom of the Perl Monks concerning the following question:
I am trying a simple graph/chart plot but I have a string which contains data that can be split with "/\s+/" however, the data with which I want to plot the graph lies in column 3 and column 4.
I tried to load the contents of $tb2 into an array @plot_data and loop through the array but I do not get what I expect. Could you please correct me from what I have done. I know its fairly simple but my bad
#!/usr/bin/env perl -l use strict; use warnings; use GD::Graph::bars; #in my code, the value of $tb2 below is returned by another function, +below is for simplicity, but this is how my string looks like. my $tb2="Date Start Time End Time Egress Sent 08-15-2013 00:22:22 00:22:29 16.53 3.85 08-15-2013 01:22:22 01:22:28 17.05 3.6 08-15-2013 02:22:23 02:22:28 16.79 3.61 08-15-2013 03:22:24 03:23:27 103.89 37.29 08-15-2013 04:22:24 04:22:26 2.1 0.18 08-15-2013 11:22:25 11:25:11 73.72 60.98 08-15-2013 12:22:25 12:27:55 146.65 133.68" ####What I tried: my @plot_data=(split '/\s+/',$tb2); for (@plot_data){ print $plot_data[1]; my @graph = ( ["$plot_data[1]"], ["$plot_data[4]"], ["$plot_data[5]"], ); } ####What I am trying to do: # my @graph = ( # [#all columns in "Egress" from $tb2, seperated by comma], # [#all columns in "Sent" from $tb2, seperated by comma], # ); for my $my_graph (GD::Graph::bars->new) { print STDERR "Processing Graph\n"; $my_graph->set( x_label => 'Timestamp', y_label => 'Data Conveyed/Sent', title => 'Conveyed Vs. Sent', long_ticks => 1, y_max_value => 200, y_tick_number => 8, y_label_skip => 2, bar_spacing => 3, shadow_depth => 4, accent_treshold => 200, transparent => 0, ); print @graph; open(IMG, '>file.gif') or die $!; binmode IMG; $my_graph->set_legend('Conveyed', 'Sent'); my $gd = $my_graph->plot(\@graph); #save_chart($my_graph, "Graph"); print IMG $gd->gif; close IMG; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Loading specific columns into arrays
by kcott (Archbishop) on Aug 16, 2013 at 09:45 UTC | |
|
Re: Loading specific columns into arrays
by poj (Abbot) on Aug 16, 2013 at 13:08 UTC | |
|
Re: Loading specific columns into arrays
by Anonymous Monk on Aug 16, 2013 at 09:44 UTC | |
by sidsinha (Acolyte) on Aug 16, 2013 at 09:47 UTC | |
by Anonymous Monk on Aug 16, 2013 at 10:15 UTC | |
|
Re: Loading specific columns into arrays
by ww (Archbishop) on Aug 16, 2013 at 11:26 UTC |