The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
=head1 NAME

Tk::Chart::FAQ - Frequently Asked Questions about Tk::Chart.

=head1 SYNOPSIS

This is the Frequently Asked Questions list for Tk::Chart. 


=head1 DESCRIPTION

=head2 How to scrolled Tk::Chart Widget ?

Tk::Chart is an extension of Canvas widget. That is an idea to scrolled your widget if you use 
Tk::Chart::Lines :

  my $line_chart = $mw->Scrolled('Lines')->pack;

You can also use B<Scrollbar> method or use scrolled frame as Pane widget like this example :

  #!/usr/bin/perl
  use strict;
  use warnings;
  use Tk;
  use Tk::Chart::Mixed;
  use Tk::Pane;
  
  my $mw = MainWindow->new(
    -title      => 'Scrolled Graph',
    -background => 'white',
  );
  
  my $pane = $mw->Scrolled(
    'Pane',
    -scrollbars => 'osoe',
    -sticky     => 'nswe',
    -width      => 300,
    -height     => 300,
  );
  $pane->Frame;
  $pane->pack(qw / -fill both -expand 1 /);
  
  my @types        = qw/ areas bars lines points bars linespoints/;
  my $chart = $pane->Mixed(
    -title      => 'My graph title',
    -xlabel     => 'X Label',
    -ylabel     => 'Y Label',
    -background => '#D0D0FF',
    -linewidth  => 2,
    -width      => 600,
    -height     => 600,
    -spacingbar => 0,
    -typemixed  => \@types,
    -markers    => [ 3, 5, 6 ],
  )->pack(qw / -fill both -expand 1 /);
  
  my @data = (
    [ '1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th' ],
    [ 90,    29,    25,    6,     -20,   1,     1,     3,     4 ],
    [ 15,    10,    5,     2,     3,     5,     7,     9,     12 ],
    [ 1,     2,     12,    6,     3,     5,     1,     23,    5 ],
    [ 15,    12,    24,    33,    19,    8,     6,     15,    21 ],
    [ 15,    2,     52,    6,     3,     17.5,  1,     43,    10 ],
    [ 30,    2,     5,     6,     3,     1.5,   1,     3,     4 ],
    [ 24,    12,    35,    20,    13,    31.5,  41,    6,     25 ],
  
  );
  
  # Add a legend to the graph
  my @legends = @types;
  $chart->set_legend(
    -title       => "Title legend",
    -data        => [ 'legend 1', 'legend 2', 'legend 3', 'legend 4', 'legend 5', 'legend 6', 'legend 7', ],
    -titlecolors => "blue",
  );
  
  # Add help identification
  $chart->set_balloon();
  
  # Create the graph
  $chart->plot( \@data );
  
  MainLoop();

B<NB:> The graph have a minimum size (by default 400x400). Then if you want to reduce this size, configure 
-width and -height option at the creation of the graph.

=head2 How to save graph in postscript, jpeg, png, gif format file ?

You can use the postscript method canvas (see L<Tk::Canvas>) to create postscript file of your image.

  $chart->postscript( -file => "MyFile.ps");

If you want to convert it in gif, jpeg format file for example, you can install L<Image::Magick> module 
and Ghostscript (L<http://pages.cs.wisc.edu/~ghost/>).

Example code for postscript file conversion:
  
  use Image::Magick;
  my $image_magick = new Image::Magick;
  $image_magick->Read("MyFile.ps");
  $image_magick->Write("MyFile.png");

=head2 How to zoom the graph in canvas widget ?

To zoom your graph, use zoom, zoomx or zoomy methods. You can create a menu zoom on the canvas.
You have an example code in L<Tk::Chart::Lines/EXAMPLES> 

=head2 Warning or fatal error messages


=head3 You must have at least 2 arrays

  eg:
  my @data = (
       [ '1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th' ],
  );
  $pie_chart->plot(\@data);
  # => you will get warning message

=head3 You must have 2 arrays in data array

You will have this warning if you use L<Tk::Chart::Pie> and if you use plot 
method with bad data.

  eg:
  my @data = (
       [ '1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th' ],
       [     1,     2,    52,    6,      3,  17.5,     1,    43,    10 ],
       [    11,    20,     2,    5,      3,     1,    12,     3,     0 ], 
  );
  $pie_chart->plot(\@data);
  
  # => you will get warning message

  my @data = (
       [ '1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th' ],
       [     1,     2,    52,    6,      3,  17.5,     1,    43,    10 ], 
  );
  $pie_chart->plot(\@data);
  # OK

=head3 Make sure that every array has the same size in plot data method

  eg:
  my @data = (
    [ 'Europe', 'Asia', 'Africa', 'Oceania', 'Americas' ], # <= 5 data 
    [ 97,       33,     3,        6,         61, 1100 ],   # <= 6 data , wrong
  );
  $pie_chart->plot(\@data);

=head3 Data not defined

  $pie_chart->plot(); # wrong

=head3 Can't set -data in set_legend method. May be you forgot to set the value

  $chart->set_legend(
    -data        => undef,     # wrong
  );

  $chart->set_legend(); # wrong

  $chart->set_legend(
    -data        => \@legends,     # OK
  );

=head3 Legend and array size data are different

  my @data = (
    [ '1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th' ],
    [ 1,     2,     5,     6,     3,     1,     1,     3,     4 ],  # legend 1
    [ 4,     2,     5,     2,     3,     5,     7,     9,     12 ], # legend 2
    [ 1,     2,     12,    6,     3,     5,     1,     23,    5 ]   # legend 3
  );
  
  my @legends = ( 'legend 1', 'legend 2', 'legend 3', 'legend 4' ); # Wrong, 
  # too much legend

  my @legends = ( 'legend 1', 'legend 2' ); # Wrong, not enough  legend

  my @legends = ( 'legend 1', 'legend 2', 'legend 3' ); # OK

=head2 When I draw a chart with high values with short interval, the Y axe does not take the minimum value of data but always 0, how to change it ?

You have to use the version B<1.14> or higher of L<Tk::Chart> and use B<-interval> or 
B<-yminvalue> and B<-ymaxvalue> options.

You can see examples in demo directory.

=head2 Where can I find some examples ?

In the B<demo> directory, you have a lot of script examples with their screenshot. 
You can see theses files on L<http://search.cpan.org/dist/Tk-Chart/MANIFEST> page of Tk::Chart.

=head1 SEE ALSO

L<Tk::Chart>

=head1 COPYRIGHT & LICENSE

Copyright 2011 Djibril Ousmanou, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.


=cut