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

In reply to Re^3: I need to create a graph from a hash using GD else GD::Graph by poj
in thread I need to create a graph from a hash using GD else GD::Graph by rahulruns

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.