Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 scrutinizing the Monastery: (5)
As of 2014-11-22 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (123 votes), past polls