To answer your second question first:

You will need to convert the date/time strings you have into epoch times, and pass them as the tick values, and then tell the program what format you want your labels to have. Here's some code that prints labels on the X-axis only for the first of each month.

my $cc = Chart::Clicker->new( width => 800, height => 300 ); my ( @k, @v, @x_tick_values ); # assumes data is in a hash keyed by dates as YYYYMMDD for my $datetime ( sort { $a <=> $b } keys %data ) { my ( $y, $m, $d ) = unpack("a4 a2 a2", $datetime); my $epoch = DateTime->new( year => $y, month => $m, day => $d )->e +poch; push @k, $epoch; push @v, $data{ $datetime }; push @x_tick_values, $epoch if $d eq '01'; } my $series = Chart::Clicker::Data::Series->new( name => 'Sales', keys => \@k, values => \@v, ); my $dataset = Chart::Clicker::Data::DataSet->new( series => [ $series +] ); $cc->add_to_datasets( $dataset ); $cc->title->text('Daily Report'); $cc->title->font->size( 20 ); $cc->title->padding->bottom( 5 ); my $context = $cc->get_context('default'); my $renderer = Chart::Clicker::Renderer::Line->new( opacity => .6 ); $renderer->brush->width( 2 ); $context->renderer( $renderer ); $context->domain_axis( Chart::Clicker::Axis::DateTime->new( format => "%Y-%m", # Specify format here. I'm using "% +Y-%m" since I # output only one label per month ticks => scalar keys %data, tick_values => \@x_tick_values, position => 'bottom', tick_label_angle => 0.78539816, # 45 deg in radians orientation => 'vertical', fudge_amount => .05, ) ); $context->range_axis->format( '%d' ); $context->range_axis->fudge_amount( .02 ); my $chart_path = "/path/to/your/chart.png"; $cc->write_output( $chart_path );

As far as non-numeric axis labels: as I mentioned, you can't, directly. As the documentation for Chart::Clicker::Data::Series states:

Despite the name (keys and values) it is expected that all keys and values will be numeric. Values is pretty obvious, but it is important that keys also be numeric, as otherwise we'd have no idea how to order the data.

If you want to use text labels for your domain's see Chart::Clicker::Axis's tick_labels method.

... which reads:

The arrayref of labels to show for ticks on this Axis. This arrayref is consulted for every tick, in order. So placing a string at the zeroeth index will result in it being displayed on the zeroeth tick, etc, etc.

Hope this helps!


The way forward always starts with a minimal test.

In reply to Re^3: chart::clicker x-axis text instead of numbers ? by 1nickt
in thread chart::clicker x-axis text instead of numbers ? by srk2992

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.