Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: I need to create a graph from a hash using GD else GD::Graph

by poj (Priest)
on Sep 11, 2013 at 09:20 UTC ( #1053434=note: print w/ replies, xml ) Need Help??


in reply to Re^2: I need to create a graph from a hash using GD else GD::Graph
in thread I need to create a graph from a hash using GD else GD::Graph

The Test::Parser::Iostat has a data method which provides a hash, no need to parse the XML. This example plots a histogram of util against elapsed time for sda2 from a file created with iostat sda2 -x 1 10 > iostat.txt.

#!/usr/bin/perl use strict; use Test::Parser::Iostat; use GD::Graph::bars; my $parser = new Test::Parser::Iostat(); open IN,'iostat.txt' or die "$!"; $parser->parse(\*IN) or die $parser->error(), "\n"; my $hash = $parser->data(); # create plot data my @plot=([],[]); for my $ar (@{$hash->{'iostat'}{'data'}}){ if ($ar->{'device'} eq 'sda2'){ push @plot[0],$ar->{'elapsed_time'}; push @plot[1],$ar->{'util'}; } } # create graph my $graph = GD::Graph::bars->new(400, 300); $graph->set( x_label => 'Elapsed time', y_label => 'Util', title => 'sda2 util', y_max_value => 100, ) or die $graph->error; my $gd = $graph->plot(\@plot) or die $graph->error; open(IMG, '>iostat.gif') or die $!; binmode IMG; print IMG $gd->gif;
poj


Comment on Re^3: I need to create a graph from a hash using GD else GD::Graph
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1053434]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2015-07-31 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls