Thanks for the tip!

In the end I used timegm() to convert my datetime to epoch seconds, and just sucked these into GD::Graph::histogram, using x_number_format to deal with the x bin label formatting as a datetime not seconds. Note that this does not get executed unless you also set x_tick_number!

Results are fine; my only gripe is that the horizontal position of the label appears to drift to the right in the bin as the bin size count increases, so that I start with a centred bin label, and end up with the label hard on the right hand side.

Here's a code snippet:

my $graph = new GD::Graph::histogram(600,600); $graph->set( x_label => 'Date and Time', y_label => 'Messages', title => 'Number of messages per bin', x_labels_vertical => 1, bar_spacing => 0, shadow_depth => 0, transparent => 0, histogram_bins => 10, show_values => 1, x_number_format => \&x_format, x_tick_number => 10, ); sub x_format { my $value = shift; # print $value . " " . localtime(int($value)) . " " . strftime( "% +Y-%m-%d %H:%M:%S", localtime(int($value))) . "\n"; # test return strftime( "%Y-%m-%d %H:%M:%S", localtime(int($value))); } my $timevalues_ref = \@timevalues_secs; my $IMG; open($IMG, '> test_plot.png'); binmode $IMG; print $IMG $graph->plot($timevalues_ref)->png; close ($IMG);

@timevalues_secs contain the timeseries data in epoch seconds.


In reply to Re^2: Bar chart of binned timestamp data by v4169sgr
in thread Bar chart of binned timestamp data by v4169sgr

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.