Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 132 lines (107 sloc) 3.585 kB
f78bc6a @gphat Initial import.
authored
1 #!/usr/bin/perl
2 use strict;
3
4 use Chart::Clicker;
5 use Chart::Clicker::Context;
6 use Chart::Clicker::Data::DataSet;
7 use Chart::Clicker::Data::Marker;
8 use Chart::Clicker::Data::Series;
9 use Chart::Clicker::Renderer::Bar;
10 use Chart::Clicker::Renderer::Point;
11 use Geometry::Primitive::Rectangle;
12 use Graphics::Color::RGB;
13
14 my $cc = Chart::Clicker->new(width => 500, height => 250, format => 'pdf');
15
16 my @hours = qw(
17 1 2 3 4 5 6 7 8 9 10 11 12
18 );
19 my @bw1 = qw(
20 5.8 5.0 4.9 4.8 4.5 4.25 3.5 2.9 2.5 1.8 .9 .8
21 );
22 my @bw2 = qw(
23 .7 1.1 1.7 2.5 3.0 4.5 5.0 4.9 4.7 4.8 4.2 4.4
24 );
25 my @bw3 = qw(
26 .3 1.4 1.2 1.5 4.0 3.5 2.0 1.9 2.7 4.2 3.2 1.1
27 );
28
29 my $series1 = Chart::Clicker::Data::Series->new(
30 keys => \@hours,
31 values => \@bw1,
32 );
33 my $series2 = Chart::Clicker::Data::Series->new(
34 keys => \@hours,
35 values => \@bw2,
36 );
37
38 # We'll create a dataset with our first two series in it...
39 my $ds = Chart::Clicker::Data::DataSet->new(
40 series => [ $series1 ]
41 );
42
43 my $ds0 = Chart::Clicker::Data::DataSet->new(
44 series => [ $series2 ]
45 );
46
47
48 # We'll put the third into it's own dataset so we can put it in a new context
49 my $series3 = Chart::Clicker::Data::Series->new(
50 keys => \@hours,
51 values => \@bw3,
52 );
53 my $ds1 = Chart::Clicker::Data::DataSet->new(
54 series => [ $series3 ]
55 );
56
57 # Create a new context
58 my $other_context = Chart::Clicker::Context->new(
59 name => 'other'
60 );
61
62 my $third_context = Chart::Clicker::Context->new(
63 name => 'third'
64 );
65
66
67 my $defctx = $cc->get_context('default');
68
69 # Set it's labels...
70 $other_context->range_axis->label('Solor');
71 $other_context->domain_axis->label('Amet');
72
73 $other_context->share_axes_with($defctx);
74 $third_context->share_axes_with($defctx);
75
76 # Instruct the ds1 dataset to use the 'other' context. DataSets default to
77 # the 'default' context.
78 $ds1->context('other');
79 $cc->add_to_contexts($other_context);
80 $ds0->context('third');
81 $cc->add_to_contexts($third_context);
82
83 # Pretty stuff
84 $cc->border->width(0);
85
86 my $grey = Graphics::Color::RGB->new(
87 red => .36, green => .36, blue => .36, alpha => 1
88 );
89 my $moregrey = Graphics::Color::RGB->new(
90 red => .71, green => .71, blue => .71, alpha => 1
91 );
92 my $orange = Graphics::Color::RGB->new(
93 red => .88, green => .48, blue => .09, alpha => 1
94 );
95 $cc->color_allocator->colors([ $grey, $moregrey, $orange ]);
96
97 # Add the datasets to the chart
98 $cc->add_to_datasets($ds);
99 $cc->add_to_datasets($ds0);
100 $cc->add_to_datasets($ds1);
101
102 $cc->plot->grid->show_domain(0);
103
104 # Set some labels on the default context
105 my $defctx = $cc->get_context('default');
106 $other_context->renderer->brush->width(2);
107 $other_context->renderer->brush->dash_pattern([qw(5 3)]);
108 $defctx->range_axis->label('Lorem');
109 $defctx->domain_axis->label('Ipsum');
110 # $defctx->domain_axis->tick_label_angle(0.785398163);
111 $defctx->range_axis->label_font->family('Hoefler Text');
112 $defctx->domain_axis->fudge_amount(.02);
113 $defctx->range_axis->tick_font->family('Gentium');
114 $defctx->domain_axis->tick_font->family('Gentium');
115 $defctx->domain_axis->label_font->family('Hoefler Text');
116
117 $cc->background_color(
118 Graphics::Color::RGB->new(red => .95, green => .94, blue => .92)
119 );
120 $cc->plot->grid->background_color->alpha(0);
121
122 # Here's the magic: You can set a renderer for any context. In this case
123 # we'll change the default to a Bar. Voila!
124 $defctx->renderer(Chart::Clicker::Renderer::Bar->new(bar_padding => 20));
125 $third_context->renderer(Chart::Clicker::Renderer::Point->new);
126 $third_context->renderer->shape->radius(7);
127
128 $cc->legend->font->family('Hoefler Text');
129
130 $cc->draw;
131 $cc->write('foo.pdf');
Something went wrong with that request. Please try again.