Here's the deal: I have 22 routers all updating a data repository. I would like to chart a variable number (user selected) of those routers' data. Typical plotting would be something like: From 1200 to 1900, show me all the counters for OID 1.1.1.1.1.1 for interface Fastethernet1/1.

I have the core of that program built but I'm having major issues plotting multiple lines to the same graph from a loop. Here's a terrible example of what I'm trying to gather.

use strict; use Chart::Gnuplot; # Date array my @x = qw( 2007-01-01 2007-01-10 2007-01-24 2007-02-01 2007-02-14 ); my @b = ([1, 2, 3, 4, 5], [6, 7, 8, 9, 10]); my @p; my @n; # Create the chart object my $chart = Chart::Gnuplot->new( output => 'datetime_1.png', xlabel => + 'Date axis', timeaxis => "x", ); # Data set object for my $i ( 1 .. 1) { @n = (); for my $j ( 0 .. $#{$b[$i]}) { print "b[$i][$j] is $b[$i][$j]\n"; push(@n,$b[$i][$j]); } my $plot = Chart::Gnuplot::DataSet->new( xdata => \@x, ydata => \@n, style => 'linespoints', timefmt => '%Y-%m-%d', ); $chart->plot2d($plot); }

The example is full of hackery and not very well built, I fully admit that. I think the issue is the chart object is receiving a new bout of state on each iteration of the loop and isn't incrementing in step with the loop. Short of manually scripting out:

$chart->plot2d($val1) if $val == 1; $chart->plot2d($val1,$val2) if $val == 2; $chart->plot2d($val1,$val2,$val3) if $val == 3; etc...

I'm not sure this is even possible. Appreciate any thoughts or suggestions.


In reply to Populate 2d Chart Using Chart::Gnuplot from a Loop by eyncydious

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.