Chart::Clicker(3pm)

๐Ÿ“ฆ
version 2.90 ยท 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– Chart::Clicker ๐Ÿ’–

okay bestie, sit DOWN, because this is the manpage for Chart::Clicker(3pm) โ€” a.k.a. User Contributed Perl Documentation, a.k.a. the charting module that makes your data look absolutely iconic. no cap.


โœจ NAME โœจ

Chart::Clicker โ€” powerful, extensible charting. that's it, that's the whole vibe. ๐Ÿฆ‹

๐ŸŒธ VERSION ๐ŸŒธ

version 2.90 โ€” she's grown, she's thriving, she's serving. ๐Ÿ’…

๐ŸŽ€ SYNOPSIS ๐ŸŽ€

here's the tea, the whole thing, copy-paste-able and adorable:

use 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');

like. look at that. a whole chart in like nine lines. main character energy fr fr. ๐Ÿ‘‘

๐ŸŒˆ DESCRIPTION ๐ŸŒˆ

Chart::Clicker wants to be a powerful, extensible charting package that makes genuinely, actually pretty output. like, output you'd show people. output you'd put on a slide and not apologize for. โœจ

Charts can be saved as png, svg, pdf and postscript. yes all of them. she contains multitudes. ๐Ÿ’œ

Clicker flexes the power of Graphics::Primitive to make snazzy graphics without being tied to any specific backend โ€” so she can switch it up whenever. and if you're new here, bestie, you probs wanna start with Chart::Clicker::Tutorial. that's the beginner-friendly doorway, walk through it. ๐Ÿšช๐Ÿฆ‹

๐Ÿ“ EXAMPLES ๐Ÿ“

for actual code examples, go look at the examples repository on GitHub:

http://github.com/gphat/chart-clicker-examples/

real code, real charts, real inspiration. go consume. ๐Ÿ˜Œ

๐Ÿ‘‘ FEATURES ๐Ÿ‘‘

๐Ÿ–Œ๏ธ Renderers

Clicker supports all of these renderers, and honestly? the range. she's got range:

  • Line
  • StackedLine
  • Bar
  • StackedBar
  • Area
  • StackedArea
  • Bubble
  • CandleStick
  • Point
  • Pie
  • PolarArea

pick your fighter. ๐Ÿ’…

๐Ÿ“Š ADDING DATA ๐Ÿ“Š

the synopsis up there shows you 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 specifically so the simple cases stay simple (as they should). and adding multiple Series to a chart? literally just change the name argument of add_data. every unique first argument becomes its own separate series. it's giving effortless. if you want the full lore, see the docs for add_data.

BUT. if you wanna use the more advanced features of Clicker, you gotta shake off the simple method and build your 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);

fun fact: this used to be the only way to add data. then everybody kept asking for the common case to be easier, and that's how add_data was born. the people spoke, Clicker listened. ๐Ÿซถ

๐Ÿงš CONTEXTS ๐Ÿงš

so normally you've got a couple datasets chillin' on the same axes. that's the standard use case. but sometimes you wanna chart one or more datasets on different axes. the classic reason? comparing two datasets of vastly different scale. like, number of employees in an office (1-10) vs. monthly revenues (10s of thousands). on a normal chart, the employee count would show up as a sad little flat line squished at the bottom. tragic. ๐Ÿ˜ญ

to fix that, Clicker has contexts. a context is a pair of axes, a renderer, and a name. and the name is the 'key' you use to refer to that context.

my $context = Chart::Clicker::Context->new( name => 'sales' );
$clicker->add_to_contexts($context);

$dataset->context('sales');

$clicker->add_to_datasets($dataset);

new contexts get a fresh domain and range axis, and they default to a Line renderer. slay. โœจ

โš ๏ธ Caveat, and this one matters: Clicker expects the default context โ€” the one identified by the string default โ€” to always be present. some of Clicker's internals pull their values straight from that context. so use the default context unless you genuinely need more than one. and if you do need more than one? use default as your base context. don't skip her, she's the foundation. ๐Ÿ’€

๐Ÿ–ผ๏ธ FORMATS & OUTPUT ๐Ÿ–ผ๏ธ

Clicker supports PNG, SVG, PDF and PostScript output. to change your output type, specify it when you create your Clicker object:

my $cc = Chart::Clicker->new(format => 'pdf', ...);
# ...
$cc->write_output('chart.pdf');

and if you're trying to get a scalar of the output for HTTP or similar shenanigans, you can do this:

# ... make your chart
$cc->draw;
my $image_data = $cc->rendered_data;

and hey โ€” if you happen to be using Catalyst, go peek at Catalyst::View::Graphics::Primitive. they already did the work, bestie. ๐ŸŒธ

๐Ÿ’Ž ATTRIBUTES ๐Ÿ’Ž

๐ŸŽจ background_color

Set/Get the background color. defaults to white.

๐Ÿ–Š๏ธ border

Set/Get the border.

๐ŸŒˆ color_allocator

Set/Get the color_allocator for this chart.

๐Ÿ—‚๏ธ contexts

Set/Get the contexts for this chart.

๐Ÿ“š datasets

Get/Set the datasets for this chart.

๐Ÿš— driver

Set/Get the driver used to render this Chart. defaults to Graphics::Primitive::Driver::Cairo.

๐Ÿ“ผ format

Get the format for this Chart. Required in the constructor. Must be one of Png, Pdf, Ps or Svg.

๐Ÿƒ plot_mode

Fast or slow plot mode. when in fast mode, data elements that are deemed superfluous or invisible just. don't get drawn. skipped. ghosted. default is 'slow'.

๐Ÿ“ grid_over

Flag controlling whether the grid is rendered over the data. defaults to 0. pro tip: you probably wanna set the grid's background color to an alpha of 0 if you turn this on.

๐Ÿ“ height

Set/Get the height. defaults to 300.

๐Ÿงฉ layout_manager

Set/Get the layout manager. defaults to Layout::Manager::Compass.

๐Ÿ—บ๏ธ legend

Set/Get the legend that will be used with this chart.

๐Ÿงญ legend_position

The position the legend will be added. should be one of north, south, east, west or center, as required by Layout::Manager::Compass.

๐Ÿ“ marker_overlay

Set/Get the marker overlay object that'll be used if this chart has markers. this one is lazily constructed, to save time. she shows up when she's needed. ๐Ÿ’…

๐ŸŽ‰ over_decorations

Set/Get an arrayref of "over decorations" โ€” i.e. things that get drawn OVER the chart. this is an advanced feature. see overaxis-bar.pl in the examples.

๐Ÿ›‹๏ธ padding

Set/Get the padding. defaults to 3px on all sides. give her some room to breathe.

๐ŸŽฌ plot

Set/Get the plot on which things are drawn.

๐ŸŒณ subgraphs

you can add "child" graphs to this one via add_subgraph. they must be Chart::Clicker objects, and they get added to the bottom of the existing chart. this is a rather esoteric feature. iykyk. ๐Ÿ™ˆ

๐Ÿท๏ธ title

Set/Get the title component for this chart. Important: this is a Graphics::Primitive::TextBox, NOT a string. so to set the title of a chart you 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 gets added to the chart at the position specified by title_position.

you should consult the documentation for Graphics::Primitive::TextBox for stuff like padding and text rotation. and if you're adding it to the top and you want some padding between it and the plot, you can:

$cc->title->padding->bottom(5);

๐Ÿงญ title_position

The position the title will be added. should be one of north, south, east, west or center, as required by Layout::Manager::Compass.

๐Ÿ“Œ Heads up: if no angle is set for the title, then it will be changed to -1.5707 if the title position is east or west. yes, automatically. she rotates herself. iconic.

๐Ÿ“ width

Set/Get the width. defaults to 500.

๐Ÿ› ๏ธ METHODS ๐Ÿ› ๏ธ

๐Ÿ”ข context_count

Get a count of contexts.

๐Ÿ“ context_names

Get a list of context names.

๐Ÿ—‘๏ธ delete_context ($name)

Remove the context with the specified name. bye bestie. ๐Ÿ‘‹

๐Ÿ” get_context ($name)

Get the context with the specified name.

๐Ÿ’พ set_context ($name, $context)

Set a context of the specified name.

๐Ÿ“ฆ add_to_datasets

Add the specified dataset (or arrayref of datasets) to the chart.

๐Ÿงฎ dataset_count

Get a count of datasets.

๐ŸŽฏ get_dataset ($index)

Get the dataset at the specified index.

๐ŸŒŠ rendered_data

Returns the data for this chart as a scalar. perfect for 'streaming' to a client. ๐ŸŒŠโœจ

๐ŸŽ€ add_to_over_decorations

Add an over decoration to the list.

๐Ÿ”Ž get_over_decoration ($index)

Get the over decoration at the specified index.

๐Ÿงพ over_decoration_count

Get a count of over decorations.

โž• add_to_contexts

Add the specified context to the chart.

๐ŸŒฟ add_subgraph

Add a subgraph to this chart.

๐Ÿ–Œ๏ธ draw

Draw this chart. do the thing. โœจ

๐Ÿ—ƒ๏ธ get_datasets_for_context

Returns an arrayref containing all datasets for the given context. this is what the renderers use to get their list of datasets to chart.

๐Ÿฐ add_data ($name, $data)

Convenience method for adding data to the chart. can be called one of three ways:

๐ŸŒŸ scalar

Passing a name and a scalar will append the scalar data to that series' data.

$cc->add_data('Sales', 1234);
$cc->add_data('Sales', 1235);

this will result in a Series named 'Sales' with two values. simple. clean.

๐ŸŒŸ arrayref

Passing a name and an arrayref works pretty much the same as the scalar method above, except it appends the supplied arrayref to the existing one. and guess what โ€” you can mix it with the scalar method. they play nice.

$cc->add_data('Sales', \@some_sales);
$cc->add_data('Sales', \@some_more_sales);
# This works still!
$cc->add_data('Sales', 1234);

๐ŸŒŸ hashref

this one lets you pass both keys and values in all at once. a whole little bundle. ๐ŸŽ

$cc->add_data('Sales', { 2009 => 1234, 2010 => 1235 });
# appends to last call
$cc->add_data('Sales', { 2011 => 1234, 2012 => 1235 });
โš ๏ธ you may call the hashref version after the scalar or arrayref versions. but you may not add a scalar or arrayref after adding a hashref โ€” because it's genuinely not clear what indices should be used for that new data. so order matters, bestie. hashref goes last. ๐Ÿ’€

๐ŸŽญ set_renderer ($renderer_object, [ $context ])

Sets the renderer on the specified context. if no context is provided, then 'default' is assumed.

โœ๏ธ write

This method is passed through to the underlying driver. you only actually need to call this if you manually called draw beforehand. most of the time you want write_output instead. just saying. ๐Ÿ‘€

๐Ÿ’พ 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, it calls draw for you โ€” she handles it.

๐Ÿšจ If you use this method, do NOT call draw first! she's already on it. doubling up is not the move.
$c->write_output('/path/to/the.png');

๐Ÿ“ inside_width

Get the width available in this container after taking away space for insets and borders.

๐Ÿ“ inside_height

Get the height available in this container after taking away space for insets and borders.

๐Ÿ’€ ISSUES WITH CENTOS ๐Ÿ’€

there have been numerous reports of problems with Chart::Clicker when using CentOS. and the fix has usually been updating the version of cairo. reports say upgrading to at least cairo-1.8.8-3 makes things actually work properly. ๐Ÿ› ๏ธ

the author hesitates to provide any other data here, because it may get out of date fast. so if you have trouble, feel free to drop an email and they'll tell you what they know.

๐Ÿ’œ CONTRIBUTORS ๐Ÿ’œ

many thanks to the individuals who contributed various bits โ€” legends, all of them:

  • Ash Berlin
  • Brian Cassidy
  • Guillermo Roditi
  • Torsten Schoenfeld
  • Yuval Kogman

๐Ÿ“‚ SOURCE ๐Ÿ“‚

Chart::Clicker is on github:

http://github.com/gphat/chart-clicker/tree/master

โœ๏ธ AUTHOR โœ๏ธ

Cory G Watson <gphat@cpan.org>


๐Ÿ‘€ okay wait โ€” this is only part 1 of 2. do not close the tab. there is more. stay tuned, bestie. ๐Ÿฆ‹๐Ÿ’–

--- ๐ŸŒธ ---

okay bestie this is the part where we give credit where credit is due, and the credit goes to Cory G Watson fr fr:

This software is copyright (c) 2016 by Cory G Watson.

and the legal tea, served fresh โ˜•:

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

so yeah โ€” you can redistribute it, you can modify it, it's giving very much open-source royalty behavior ๐Ÿ‘‘, just keep it on the same terms as perl itself. no cap, that's the whole vibe. slay ๐Ÿ’…


๐ŸŽ€ and that's a wrap on Chart::Clicker(3pm), bestie!! this little icon of a manpage rode in on perl v5.36.0, dated 2022-10-14, and it ate every single time โœจ๐Ÿฆ‹ go forth and make the prettiest charts, you absolute main character ๐Ÿ’œ๐Ÿ“๐Ÿงš

k bye love u, go plot something gorgeous ๐Ÿ’–

๐Ÿ“ฆ where this page comes from