| 1 | package Chart::Clicker::Tutorial; | ||
| 2 | $Chart::Clicker::Tutorial::VERSION = '2.89'; | ||
| 3 | # ABSTRACT: A Tutorial for using Chart::Clicker | ||
| 4 | |||
| 5 | |||
| 6 | 1; | ||
| 7 | |||
| 8 | __END__ | ||
| 9 | |||
| 10 | =pod | ||
| 11 | |||
| 12 | =head1 NAME | ||
| 13 | |||
| 14 | Chart::Clicker::Tutorial - A Tutorial for using Chart::Clicker | ||
| 15 | |||
| 16 | =head1 VERSION | ||
| 17 | |||
| 18 | version 2.89 | ||
| 19 | |||
| 20 | =head1 DESCRIPTION | ||
| 21 | |||
| 22 | This document aims to provide a tutorial for using Chart::Clicker. | ||
| 23 | |||
| 24 | =head1 EXAMPLES | ||
| 25 | |||
| 26 | =head2 Simple chart from a single data source | ||
| 27 | |||
| 28 | # grab the needed modules | ||
| 29 | use Chart::Clicker; | ||
| 30 | use Chart::Clicker::Data::Series; | ||
| 31 | use Chart::Clicker::Data::DataSet; | ||
| 32 | |||
| 33 | # build the chart | ||
| 34 | my $chart = Chart::Clicker->new; | ||
| 35 | |||
| 36 | # build the series (static here, will usually be supplied arrayrefs from elsewhere) | ||
| 37 | my $series = Chart::Clicker::Data::Series->new( | ||
| 38 | keys => [ 1,2,3,4,5 ], | ||
| 39 | values => [ 52,74,52,82,14 ], | ||
| 40 | ); | ||
| 41 | |||
| 42 | # build the dataset | ||
| 43 | my $dataset = Chart::Clicker::Data::DataSet->new( | ||
| 44 | series => [ $series ], | ||
| 45 | ); | ||
| 46 | |||
| 47 | # add the dataset to the chart | ||
| 48 | $chart->add_to_datasets($dataset); | ||
| 49 | |||
| 50 | # write the chart to a file | ||
| 51 | $chart->write_output('chart.png'); | ||
| 52 | |||
| 53 | =head2 Simple chart from multiple data sources | ||
| 54 | |||
| 55 | use Chart::Clicker; | ||
| 56 | use Chart::Clicker::Data::Series; | ||
| 57 | use Chart::Clicker::Data::DataSet; | ||
| 58 | |||
| 59 | my $chart = Chart::Clicker->new; | ||
| 60 | |||
| 61 | # start an array that will hold the series data | ||
| 62 | my $series1 = Chart::Clicker::Data::Series->new( | ||
| 63 | keys => [ 1,2,3,4,5 ], | ||
| 64 | values => [ 52,74,52,82,14 ] | ||
| 65 | ); | ||
| 66 | my $series2 = Chart::Clicker::Data::Series->new( | ||
| 67 | keys => [ 1,2,3,4,5 ], | ||
| 68 | values => [ 34,67,89,45,67 ] | ||
| 69 | ); | ||
| 70 | |||
| 71 | # add the array of series data to the dataset | ||
| 72 | my $dataset = Chart::Clicker::Data::DataSet->new( | ||
| 73 | series => [ $series1, $series2 ] | ||
| 74 | ); | ||
| 75 | |||
| 76 | $chart->add_to_datasets($dataset); | ||
| 77 | |||
| 78 | $chart->write_output('chart.png'); | ||
| 79 | |||
| 80 | =head2 Simple chart with multiple data sources and custom colors | ||
| 81 | |||
| 82 | use Chart::Clicker; | ||
| 83 | use Chart::Clicker::Data::Series; | ||
| 84 | use Chart::Clicker::Data::DataSet; | ||
| 85 | # some new modules, these are only needed if you want to monkey with color changing | ||
| 86 | use Graphics::Color::RGB; | ||
| 87 | use Chart::Clicker::Drawing::ColorAllocator; | ||
| 88 | |||
| 89 | # build the color allocator | ||
| 90 | my $ca = Chart::Clicker::Drawing::ColorAllocator->new; | ||
| 91 | # this hash is simply here to make things readable and cleaner, you can always call G::C::R inline | ||
| 92 | my $red = Graphics::Color::RGB->new({ | ||
| 93 | red => .75, green => 0, blue => 0, alpha => .8 | ||
| 94 | }); | ||
| 95 | my $green = Graphics::Color::RGB->new({ | ||
| 96 | red => 0,green => .75, blue=> 0, alpha=> .8 | ||
| 97 | }); | ||
| 98 | my $blue = Graphics::Color::RGB->new({ | ||
| 99 | red => 0, green => 0, blue => .75, alpha => .8 | ||
| 100 | }), | ||
| 101 | |||
| 102 | my $chart = Chart::Clicker->new; | ||
| 103 | |||
| 104 | # Create an empty dataset that we can add to | ||
| 105 | my $dataset = Chart::Clicker::Data::DataSet->new; | ||
| 106 | |||
| 107 | $dataset->add_to_series(Chart::Clicker::Data::Series->new( | ||
| 108 | keys => [ 1,2,3,4,5 ], | ||
| 109 | values => [ 52,74,52,82,14 ] | ||
| 110 | )); | ||
| 111 | # add a color - note that the order of colors and the order of the | ||
| 112 | # series must match, the first series will use the first color and so on | ||
| 113 | # see contexts and axes for alternate ways of doing this | ||
| 114 | $ca->add_to_colors($blue); | ||
| 115 | |||
| 116 | $dataset->add_to_series(Chart::Clicker::Data::Series->new( | ||
| 117 | keys => [ 1,2,3,4,5 ], | ||
| 118 | values => [ 34,67,89,45,67 ] | ||
| 119 | )); | ||
| 120 | # add a second color | ||
| 121 | $ca->add_to_colors($red); | ||
| 122 | |||
| 123 | $dataset->add_to_series(Chart::Clicker::Data::Series->new( | ||
| 124 | keys => [ 1,2,3,4,5 ], | ||
| 125 | values => [ 11,22,33,44,55 ] | ||
| 126 | )); | ||
| 127 | # add a third color | ||
| 128 | $ca->add_to_colors($green); | ||
| 129 | |||
| 130 | $chart->add_to_datasets($dataset); | ||
| 131 | |||
| 132 | # assign the color allocator to the chart | ||
| 133 | $chart->color_allocator($ca); | ||
| 134 | |||
| 135 | $chart->write_output('chart.png'); | ||
| 136 | |||
| 137 | =head2 Example 4 : Simple chart with a different render type | ||
| 138 | |||
| 139 | use Chart::Clicker; | ||
| 140 | use Chart::Clicker::Data::Series; | ||
| 141 | use Chart::Clicker::Data::DataSet; | ||
| 142 | # add in the module of the renerer(s) you want to use | ||
| 143 | use Chart::Clicker::Renderer::Area; | ||
| 144 | |||
| 145 | my $chart = Chart::Clicker->new; | ||
| 146 | |||
| 147 | my $series = Chart::Clicker::Data::Series->new( | ||
| 148 | keys => [ 1,2,3,4,5 ], | ||
| 149 | values => [ 52,74,52,82,14 ] | ||
| 150 | ); | ||
| 151 | |||
| 152 | my $dataset = Chart::Clicker::Data::DataSet->new( | ||
| 153 | series => [ $series ] | ||
| 154 | ); | ||
| 155 | |||
| 156 | $chart->add_to_datasets($dataset); | ||
| 157 | |||
| 158 | # build the renderer to use | ||
| 159 | my $renderer = Chart::Clicker::Renderer::Area->new( | ||
| 160 | opacity => .75, | ||
| 161 | ); | ||
| 162 | |||
| 163 | # assign the renderer to the default context | ||
| 164 | $chart->set_renderer($renderer); | ||
| 165 | |||
| 166 | $chart->write_output('chart.png'); | ||
| 167 | |||
| 168 | =head2 Example 5 : Width and Height | ||
| 169 | |||
| 170 | my $chart = Chart::Clicker->new(width => 1024, height => 768); | ||
| 171 | |||
| 172 | =head2 Example 6 : PDF (or SVG or PS) | ||
| 173 | |||
| 174 | my $chart = Chart::Clicker->new(format => 'pdf'); | ||
| 175 | |||
| 176 | # Create the rest of your chart normally | ||
| 177 | |||
| 178 | $chart->write_output('chart.pdf'); | ||
| 179 | |||
| 180 | =head2 Example 7 : Hide the Legend and X-Axis | ||
| 181 | |||
| 182 | my $chart = Chart::Clicker->new; | ||
| 183 | |||
| 184 | # hide the legend | ||
| 185 | $chart->legend->visible(0); | ||
| 186 | |||
| 187 | # hide the X-Axis | ||
| 188 | $chart->get_context('default')->domain_axis->hidden(1); | ||
| 189 | |||
| 190 | =head2 Example 8 : Change the display format of the Y-Axis | ||
| 191 | |||
| 192 | my $chart = Chart::Clicker->new; | ||
| 193 | |||
| 194 | # a sprintf format to have 3 decimal places showing on the Y-Axis | ||
| 195 | $chart->get_context('default')->range_axis->format('%.3f'); | ||
| 196 | |||
| 197 | =begin :postlude | ||
| 198 | |||
| 199 | =head1 CONTRIBUTORS | ||
| 200 | |||
| 201 | Steve Bradford | ||
| 202 | |||
| 203 | Michael Peters | ||
| 204 | |||
| 205 | =end :postlude | ||
| 206 | |||
| 207 | =head1 DISCLAIMER | ||
| 208 | |||
| 209 | This is a work in progress. If you find errors or would like to make | ||
| 210 | contributions, drop me a line! | ||
| 211 | |||
| 212 | =head1 AUTHOR | ||
| 213 | |||
| 214 | Cory G Watson <gphat@cpan.org> | ||
| 215 | |||
| 216 | =head1 COPYRIGHT AND LICENSE | ||
| 217 | |||
| 218 | This software is copyright (c) 2016 by Cory G Watson. | ||
| 219 | |||
| 220 | This is free software; you can redistribute it and/or modify it under | ||
| 221 | the same terms as the Perl 5 programming language system itself. | ||
| 222 | |||
| 223 | =cut |