Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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