Perobl has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!

I'm trying to figure out Chart::Clicker. The supporting documentation seems a bit thin.

I have everything working except for my axes. I am able to display domain_axis tick_labels save for the fact that some of the tick_labels appear to be "chopped off". For example, a tick_label that should say "Q 2" displays as "Q".

Further, the domain_axis label itself is limited to only a few characters. If I exceed a certain number of characters, the chart won't display at all.

I'm unable to display my range axis at all! As soon as I set hidden to zero, the chart disappears.

My code follows:

# --------------------------------------------------- # create the survey 1 mean chart using Chart::Clicker # --------------------------------------------------- # instantiate new Chart::Clicker object my $cc = Chart::Clicker -> new(width => 800, height => 400); # define ticks, series and dataset for chart my $ticks = {labels => ['Q 1A', 'Q 2', 'Q 3', 'Q 4', 'Q 5', 'Q 6A'], " +values" => [1, 2, 3, 4, 5, 6],}; my $series = Chart::Clicker::Data::Series -> new(keys => $ticks -> {va +lues}, values => \@qavg); my $ds = Chart::Clicker::Data::DataSet -> new(series => [$series],); # define Chart::Clicker context my $context = $cc -> get_context('default'); $context -> range_axis -> hidden(1); $context -> range_axis -> fudge_amount(.01); $context -> range_axis -> ticks(5); $context -> range_axis -> range -> min(0); $context -> range_axis -> range -> max(5); $context -> range_axis -> label('Survey Scores'); $context -> range_axis -> brush -> width(1); $context -> domain_axis -> hidden(0); $context -> domain_axis -> fudge_amount(.1); $context -> domain_axis -> baseline(1); $context -> domain_axis -> tick_values($ticks -> {values}); $context -> domain_axis -> tick_labels($ticks -> {labels}); $context -> domain_axis -> tick_label_angle(); $context -> domain_axis -> label("Survey Questions"); $context -> domain_axis -> brush -> width(1); # define data allocator for the chart's bar color my $ca = Chart::Clicker::Drawing::ColorAllocator -> new(); my $blue = Graphics::Color::RGB -> new({red => .15, green => .3, blue +=> .5, alpha => .75}); $ca -> add_to_colors($blue); # instantiate a new renderer (bar chart) my $renderer = Chart::Clicker::Renderer::Bar -> new(); # finish setting the chart parameters $cc -> add_to_datasets($ds); $cc -> set_renderer($renderer); $cc -> color_allocator($ca); $cc -> border -> width(1); $cc -> legend -> visible(0); # define chart title $cc -> title -> text('Dynamic Charting: Survey 1 - Front End of Busine +ss (Mean Analysis)'); $cc -> title -> font -> size(20); $cc -> title -> padding -> bottom(10); # render the chart $cc -> draw; $cc -> write('/home/wiw/public_html/tmp/s1avg.png');
Can anyone lend me a hand? Thank you!

Replies are listed 'Best First'.
Re: Chart::Clicker Question
by Khen1950fx (Canon) on Oct 30, 2010 at 13:03 UTC
    I tried this. I had to make some changes to get it to work, but this is as close as I could get.
    #!/usr/bin/perl use strict; use warnings; use Chart::Clicker; use Chart::Clicker::Context; use Chart::Clicker::Data::DataSet; use Chart::Clicker::Data::Marker; use Chart::Clicker::Data::Series; use Chart::Clicker::Renderer::Bar; use Geometry::Primitive::Rectangle; use Graphics::Color::RGB; my $cc = Chart::Clicker->new(width => 500, height => 250); my $series = Chart::Clicker::Data::Series->new( keys => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], values => [ 4, 5.6, 7.9, 9, 13, 17, 23, 35, 46, 50 ], ); my $ds = Chart::Clicker::Data::DataSet->new(series => [$series]); $cc->add_to_datasets($ds); my $def = $cc->get_context('default'); my $area = Chart::Clicker::Renderer::Bar->new(opacity => .6); $area->brush->width(3); $def->renderer($area); $def->range_axis->tick_values([qw(1 3 5)]); $def->range_axis->label('Scores'); $def->range_axis->format('%d'); $def->domain_axis->tick_values([qw(2 4 6 8 10)]); $def->domain_axis->label('Survey Questions'); $def->domain_axis->format('%d'); $def->domain_axis->fudge_amount(.05); $cc->title->text('Dynamic Charting: Survey 1 - Front En +d '); $cc->title->font->size(20); $cc->title->padding->bottom(10); $cc->write_output('Dynamic Charting: Survey 1.png');

      Thanks so much for your help!

      I'm pulling my hair out with Chart::Clicker.

      I copied your code to my server and ran it. On my server, the resulting .PNG is simply a white rectangle with one thin horizontal line running along the bottom.

      This is typical of the output I usually see. When I run the tutorial programs on CPAN, I get the same sort of results.

      Do you think there might be a problem with the Chart::Clicker installation on my server? I've taken great care to load ALL of the prerequisite Perl modules. I did have some trouble getting Cairo loaded, but the server now reports that all modules are loaded okay (via CPanel). It just seems like things aren't working right (i.e. it seems like I'm not getting the results you are getting).

      My own program produces a chart that is about 85% complete. Like I said, some of the tick labels are incomplete. And no matter what I do, I cannot get the vertical axis to work!

      I am totally stuck, and I'd rather not pull the plug on this because I have too much time invested and need a good charting solution.

      Any other suggestions?

        Here's a bundle to check to see that you have all the prerequisites.
        #!/usr/bin/perl use strict; use warnings; use CPAN; CPAN::Shell->install( "Test::PDF", "ExtUtils::PkgConfig", "ExtUtils::Depends", "Cairo", "Test::LongString", "Text::Flow", "Graphics::Primitive::Driver::Cairo", "Math::Gradient", "Set::Infinite", "DateTime::Set", "Algorithm::Diff", "Text::Diff", "Test::Differences", "Color::Scheme", "Class::Data::Inheritable", "Class::Accessor::Fast", "Module::Pluggable", "Color::Library", "Test::Number::Delta", "MooseX::Aliases", "Graphics::Color", "Forest", "Graphics::Primitive", "MooseX::AttributeHelpers", "JSON::Any", "File::Path", "File::NFSLock", "IO::Dir", "Path::Class", "Carp::Clan", "MooseX::Types", "MooseX::Types::Path::Class", "Test::TempDir", "Test::NoWarnings", "Test::Tester", "Test::Deep", "String::RewritePrefix", "MooseX::Storage", "Math::Complex", "Check::ISA", "Hash::Util::FieldHash::Compat", "Algorithm::C3", "Class::C3", "MRO::Compat", "Scope::Guard", "Devel::GlobalDestruction", "Class::MOP", "Try::Tiny", "Moose", "Task::Weaken", "XSLoader", "base", "Variable::Magic", "Data::OptList", "Sub::Install", "Params::Util", "Sub::Exporter", "B::Hooks::EndOfScope", "Sub::Identify", "Sub::Name", "Package::Stash", "namespace::clean", "Tie::RefHash", "Test::use::ok", "Tie::ToObject", "Data::Visitor", "MooseX::Clone", "Geometry::Primitive", "ExtUtils::MakeMaker", "Layout::Manager", "Time::Local", "List::MoreUtils", "DateTime::Locale", "File::Temp", "Exporter", "ExtUtils::ParseXS", "Module::Build", "Attribute::Handlers", "ExtUtils::CBuilder", "Params::Validate", "Class::Singleton", "DateTime::TimeZone", "Test", "Text::Wrap", "Pod::Escapes", "Pod::Simple", "File::Spec", "Pod::Man", "Sub::Uplevel", "Test::Exception", "Test::Harness", "Test::More", "Scalar::Util", "DateTime", "Chart::Clicker");