Chart::Clicker is a Perl module for creating charts and graphs. It aims to provide a powerful and extensible charting package that produces high-quality output in formats like PNG, SVG, PDF and Postscript. Chart::Clicker uses Moose classes and Cairo for rendering. It supports various chart types through different renderer objects. Contexts contain axes, renderers and associate datasets to those axes. Colors can be customized using color allocators. Configuration modules can be used to soft code chart properties.
19. Chart::Clicker components Clicker Object Handles titles, datasets, data writes, contexts. Series Objects X data (keys), Y data (values), labels Dataset objects Contain 1 or more series objects, and will be assigned a context. DON'T AVOID using Series and Datasets. Otherwise you'll be stuck with trivial graphs.
20. my $cc = Chart::Clicker->new( format =>'png', height => 480, width => 640 ); my $series1 = Chart::Clicker::Data::Series->new( keys => x_data,, values => y_data, ); $series1->name('First Line'); # # lots more series # my $ds = Chart::Clicker::Data::DataSet->new( series => [ $series1, $series2, $series3, $series4, $series5, $series6, $series7, $series8 ] ); $cc->add_to_datasets($ds);
21. Axes and Contexts Contexts contain 2 axes, a renderer, and a name. Contexts can/will be assigned to a dataset.
26. StackedArea, StackedBar, PolarArea, CandleStick, HeatMap, etc. The default renderer is a line. If you don't see one initialized, that's why.
27. my $context = Chart::Clicker::Context->new( name => 'sales' ); $clicker->add_to_contexts($context); $dataset->context('sales'); $clicker->add_to_datasets($dataset);
28. # # Creating a context and then setting up Axis values. # %cfg values are assigned via a Config::Simple object. # my $defctx = $cc->get_context('default'); $defctx->domain_axis->label($cfg{"default.X_Axis"}); $defctx->domain_axis->range( Chart::Clicker::Data::Range->new( lower => $cfg{"default.X_Lower"}, upper => $cfg{"default.X_Upper"} ) ); $defctx->domain_axis->ticks( $cfg{"default.X_Ticks"}); $defctx->range_axis->label($cfg{"default.Y_Axis"}); $defctx->range_axis->range( Chart::Clicker::Data::Range->new( lower => $cfg{"default.Y_Lower"}, upper => $cfg{"default.Y_Upper"} ) ); $defctx->range_axis->ticks($cfg{"default.Y_Ticks"}); $defctx->renderer(Chart::Clicker::Renderer::Point->new);
29. Contexts: sharing axes Contexts can share axes. The Chart::Clicker::Context perldocs shows this method: $context_a->share_axes_with($context_b); Also possible is $self->range_axis($other_context->range_axis); $self->domain_axis($other_context->domain_axis);
31. That said, Chart::Clicker::Drawing::ColorAllocator exists. The Allocator is designed to choose color values equally spaced on the color chart. Colors can specified with rgb floating point values and an alpha value (floating) (object), or by a number between 0 and 359. Red = 0, Green = 180, Yellow = 90, Blue = 270
33. More color notes By creating color objects and then using the method add_to_colors with your ColorAllocator, then those colors will be stacked in order of the series collected in your dataset.
34. Named colors can be accessed through the from_color_library method of the Graphics::Color::RGB object.
35. my $ca = Chart::Clicker::Drawing::ColorAllocator->new; # this hash is simply here to make things readable and cleaner, you can always call G::C::R inline my $red = Graphics::Color::RGB->new({ red => .75, green => 0, blue => 0, alpha => .8 }); my $green = Graphics::Color::RGB->new({ red => 0,green => .75, blue=> 0, alpha=> .8 }); my $blue = Graphics::Color::RGB->new({ red => 0, green => 0, blue => .75, alpha => .8 }), my $chart = Chart::Clicker->new; # Create an empty dataset that we can add to my $dataset = Chart::Clicker::Data::DataSet->new; $dataset->add_to_series(Chart::Clicker::Data::Series->new( keys => [ 1,2,3,4,5 ], values => [ 52,74,52,82,14 ] )); # add a color - note that the order of colors and the order of the # series must match, the first series will use the first color and so on # see contexts and axes for alternate ways of doing this $ca->add_to_colors($blue);
36. # # if $colorlist non-empty, it contains Color::Library # colors. # if ( scalar @{$colorlist} > 0 ) { my $rgb = new Graphics::Color::RGB; my $colors; for (@{$colorlist}) { push @{$colors}, $rgb->from_color_library( $_ ); } my $ca = Chart::Clicker::Drawing::ColorAllocator->new( { colors => $colors }); $cc->color_allocator( $ca ); }
37. Complementary Tools Configuration Modules – soft code your graphs. Config::Simple, Config::General, etc. PDL and PDL::Stats – curve fitting, numerical methods, statistics.
38. Image::Magick – The Annotate method can be used to label graphs (will have to DIY the Geometry)