Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

stacked bar

  • Loading branch information...
commit d4354b4ed1f4ab1123595508f19c87a42aecc19f 1 parent d00d71e
@gphat authored
Showing with 64 additions and 0 deletions.
  1. +64 −0 bar/stacked-bar.pl
  2. BIN  bar/stacked-bar.png
View
64 bar/stacked-bar.pl
@@ -0,0 +1,64 @@
+#!/usr/bin/perl
+use strict;
+
+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::StackedBar;
+use Geometry::Primitive::Rectangle;
+use Graphics::Color::RGB;
+
+my $cc = Chart::Clicker->new(width => 500, height => 250);
+
+my @hours = qw(
+ 1 2 3 4 5 6 7 8 9 10 11 12
+);
+my @bw1 = qw(
+ 5.8 5.0 4.9 4.8 4.5 4.25 3.5 2.9 2.5 1.8 .9 .8
+);
+my @bw2 = qw(
+ .7 1.1 1.7 2.5 3.0 4.5 5.0 4.9 4.7 4.8 4.2 4.4
+);
+my @bw3 = qw(
+ .3 1.4 1.2 1.5 4.0 3.5 2.0 1.9 2.7 4.2 3.2 1.1
+);
+
+my $series1 = Chart::Clicker::Data::Series->new(
+ keys => \@hours,
+ values => \@bw1,
+);
+my $series2 = Chart::Clicker::Data::Series->new(
+ keys => \@hours,
+ values => \@bw2,
+);
+
+my $series3 = Chart::Clicker::Data::Series->new(
+ keys => \@hours,
+ values => \@bw3,
+);
+
+$cc->title->text('Stacked Bar');
+$cc->title->padding->bottom(5);
+
+my $ds = Chart::Clicker::Data::DataSet->new(series => [ $series1, $series2, $series3 ]);
+
+$cc->add_to_datasets($ds);
+
+my $def = $cc->get_context('default');
+
+my $area = Chart::Clicker::Renderer::StackedBar->new(opacity => .8);
+$area->brush->width(3);
+$def->renderer($area);
+$def->range_axis->tick_values([qw(1 3 5 7 9 11)]);
+$def->range_axis->format('%d');
+$def->domain_axis->tick_values([qw(1 3 5 7 9 11)]);
+$def->domain_axis->format('%d');
+
+# We ask clicker to "fudge" the edges with some padding so that the bars show
+# up properly.
+$def->domain_axis->fudge_amount(.05);
+$def->range_axis->fudge_amount(.01);
+
+$cc->write_output('stacked-bar.png');
View
BIN  bar/stacked-bar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.