|
NAMEChart::Clicker - Powerful, extensible charting.VERSIONversion 2.90SYNOPSISuse Chart::Clicker; my $cc = Chart::Clicker->new; my @values = (42, 25, 86, 23, 2, 19, 103, 12, 54, 9); $cc->add_data('Sales', \@values); # alternately, you can add data one bit at a time... foreach my $v (@values) { $cc->add_data('Sales', $v); } # Or, if you want to specify the keys you can use a hashref my $data = { 12 => 123, 13 => 341, 14 => 1241 }; $cc->add_data('Sales', $data); $cc->write_output('foo.png'); DESCRIPTIONChart::Clicker aims to be a powerful, extensible charting package that creates really pretty output. Charts can be saved in png, svg, pdf and postscript format.Clicker leverages the power of Graphics::Primitive to create snazzy graphics without being tied to specific backend. You may want to begin with Chart::Clicker::Tutorial. EXAMPLESFor code examples see the examples repository on GitHub: <http://github.com/gphat/chart-clicker-examples/>FEATURESRenderersClicker supports the following renderers:
ADDING DATAThe synopsis shows the simple way to add data.my @values = (42, 25, 86, 23, 2, 19, 103, 12, 54, 9); foreach my $v (@values) { $cc->add_data('Sales', $v); } This is a convenience method provided to make simple cases much simpler. Adding multiple Series to a chart is as easy as changing the name argument of "add_data". Each unique first argument will result in a separate series. See the docs for "add_data" to learn more. If you'd like to use the more advanced features of Clicker you'll need to shake off this simple method and build Series & DataSets explicitly. use Chart::Clicker::Data::Series; use Chart::Clicker::Data::DataSet; ... my $series = Chart::Clicker::Data::Series->new( keys => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], values => [ 42, 25, 86, 23, 2, 19, 103, 12, 54, 9 ], ); my $ds = Chart::Clicker::Data::DataSet->new(series => [ $series ]); $cc->add_to_datasets($ds); This used to be the only way to add data, but repeated requests to make the common case easier resulted in the inclusion of "add_data". CONTEXTSThe normal use case for a chart is a couple of datasets on the same axes. Sometimes you want to chart one or more datasets on different axes. A common need for this is when you are comparing two datasets of vastly different scale such as the number of employees in an office (1-10) to monthly revenues (10s of thousands). On a normal chart the number of employees would show up as a flat line at the bottom of the chart.To correct this, Clicker has contexts. A context is a pair of axes, a renderer and a name. The name is the 'key' by which you will refer to the context. my $context = Chart::Clicker::Context->new( name => 'sales' ); $clicker->add_to_contexts($context); $dataset->context('sales'); $clicker->add_to_datasets($dataset); New contexts provide a fresh domain and range axis and default to a Line renderer. Caveat: Clicker expects that the default context (identified by the string "default") will always be present. It is from this context that some of Clicker's internals draw their values. You should use the default context unless you need more than one, in which case you should use "default" as the base context. FORMATS & OUTPUTClicker supports PNG, SVG, PDF and PostScript output. To change your output type, specificy it when you create your Clicker object:my $cc = Chart::Clicker->new(format => 'pdf', ...); # ... $cc->write_output('chart.pdf'); If you are looking to get a scalar of the output for use with HTTP or similar things, you can use: # ... make your chart $cc->draw; my $image_data = $cc->rendered_data; If you happen to be using Catalyst then take a look at Catalyst::View::Graphics::Primitive. ATTRIBUTESbackground_colorSet/Get the background color. Defaults to white.borderSet/Get the border.color_allocatorSet/Get the color_allocator for this chart.contextsSet/Get the contexts for this chart.datasetsGet/Set the datasets for this chart.driverSet/Get the driver used to render this Chart. Defaults to Graphics::Primitive::Driver::Cairo.formatGet the format for this Chart. Required in the constructor. Must be on of Png, Pdf, Ps or Svg.plot_modeFast or slow plot mode. When in fast mode, data elements that are deemed to be superfluous or invisible will not be drawn. Default is 'slow'grid_overFlag controlling if the grid is rendered over the data. Defaults to 0. You probably want to set the grid's background color to an alpha of 0 if you enable this flag.heightSet/Get the height. Defaults to 300.layout_managerSet/Get the layout manager. Defaults to Layout::Manager::Compass.legendSet/Get the legend that will be used with this chart.legend_positionThe position the legend will be added. Should be one of north, south, east, west or center as required by Layout::Manager::Compass.marker_overlaySet/Get the marker overlay object that will be used if this chart has markers. This is lazily constructed to save time.over_decorationsSet/Get an arrayref of "over decorations", or things that are drawn OVER the chart. This is an advanced feature. See "overaxis-bar.pl" in the examples.paddingSet/Get the padding. Defaults to 3px on all sides.plotSet/Get the plot on which things are drawn.subgraphsYou can add "child" graphs to this one via "add_subgraph". These must be Chart::Clicker objects and they will be added to the bottom of the existing chart. This is a rather esoteric feature.titleSet/Get the title component for this chart. This is a Graphics::Primitive::TextBox, not a string. To set the title of a chart you should access the TextBox's "text" method.$cc->title->text('A Title!'); $cc->title->font->size(20); # etc, etc If the title has text then it is added to the chart in the position specified by "title_position". You should consult the documentation for Graphics::Primitive::TextBox for things like padding and text rotation. If you are adding it to the top and want some padding between it and the plot, you can: $cc->title->padding->bottom(5); title_positionThe position the title will be added. Should be one of north, south, east, west or center as required by Layout::Manager::Compass.Note that if no angle is set for the title then it will be changed to -1.5707 if the title position is east or west. widthSet/Get the width. Defaults to 500.METHODScontext_countGet a count of contexts.context_namesGet a list of context names.delete_context ($name)Remove the context with the specified name.get_context ($name)Get the context with the specified nameset_context ($name, $context)Set a context of the specified name.add_to_datasetsAdd the specified dataset (or arrayref of datasets) to the chart.dataset_countGet a count of datasets.get_dataset ($index)Get the dataset at the specified index.rendered_dataReturns the data for this chart as a scalar. Suitable for 'streaming' to a client.add_to_over_decorationsAdd an over decoration to the list.get_over_decoration ($index)Get the over decoration at the specified index.over_decoration_countGet a count of over decorations.add_to_contextsAdd the specified context to the chart.add_subgraphAdd a subgraph to this chart.drawDraw this chart.get_datasets_for_contextReturns an arrayref containing all datasets for the given context. Used by renderers to get a list of datasets to chart.add_data ($name, $data)Convenience method for adding data to the chart. Can be called one of three ways.
set_renderer ($renderer_object, [ $context ]);Sets the renderer on the specified context. If no context is provided then 'default' is assumed.writeThis method is passed through to the underlying driver. It is only necessary that you call this if you manually called "draw" beforehand. You likely want to use "write_output".write_output ($path)Write the chart output to the specified location. Output is written in the format provided to the constructor (which defaults to Png). Internally calls "draw" for you. If you use this method, do not call "draw" first!$c->write_output('/path/to/the.png'); inside_widthGet the width available in this container after taking away space for insets and borders.inside_heightGet the height available in this container after taking away space for insets and borders.ISSUES WITH CENTOSI've had numerous reports of problems with Chart::Clicker when using CentOS. This problem has usually be solved by updating the version of cairo. I've had reports that upgrading to at least cairo-1.8.8-3 makes thinks work properly.I hesitate to provide any other data with this because it may get out of date fast. If you have trouble feel free to drop me an email and I'll tell you what I know. CONTRIBUTORSMany thanks to the individuals who have contributed various bits:Ash Berlin Brian Cassidy Guillermo Roditi Torsten Schoenfeld Yuval Kogman SOURCEChart::Clicker is on github:http://github.com/gphat/chart-clicker/tree/master AUTHORCory G Watson <gphat@cpan.org>COPYRIGHT AND LICENSEThis software is copyright (c) 2016 by Cory G Watson.This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Visit the GSP FreeBSD Man Page Interface. |