1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| use Chart::Clicker;
use Chart::Clicker::Data::Series;
use Chart::Clicker::Data::DataSet;
# some new modules, these are only needed if you want to monkey with color changing
use Graphics::Color::RGB;
use Chart::Clicker::Drawing::ColorAllocator;
# build the color allocator
my $ca = Chart::Clicker::Drawing::ColorAllocator->new;
# this hash is simply here to make things readable and cleaner, you can always call G::C::R inline
my $red = Graphics::Color::RGB->new({
red => .75, green => 0, blue => 0, alpha => .8
});
my $green = Graphics::Color::RGB->new({
red => 0,green => .75, blue=> 0, alpha=> .8
});
my $blue = Graphics::Color::RGB->new({
red => 0, green => 0, blue => .75, alpha => .8
}),
my $chart = Chart::Clicker->new;
# Create an empty dataset that we can add to
my $dataset = Chart::Clicker::Data::DataSet->new;
$dataset->add_to_series(Chart::Clicker::Data::Series->new(
keys => [ 1,2,3,4,5 ],
values => [ 52,74,52,82,14 ]
));
# add a color - note that the order of colors and the order of the
# series must match, the first series will use the first color and so on
# see contexts and axes for alternate ways of doing this
$ca->add_to_colors($blue);
$dataset->add_to_series(Chart::Clicker::Data::Series->new(
keys => [ 1,2,3,4,5 ],
values => [ 34,67,89,45,67 ]
));
# add a second color
$ca->add_to_colors($red);
$dataset->add_to_series(Chart::Clicker::Data::Series->new(
keys => [ 1,2,3,4,5 ],
values => [ 11,22,33,44,55 ]
));
# add a third color
$ca->add_to_colors($green);
$chart->add_to_datasets($dataset);
# assign the color allocator to the chart
$chart->color_allocator($ca);
$chart->write_output('chart.png'); |
Partager