Area.pm 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. # DISCLAIMER OF WARRANTY
  2. # Because this software is licensed free of charge, there is no warranty for the software,
  3. # to the extent permitted by applicable law. Except when otherwise stated in writing
  4. # the copyright holders and/or other parties provide the software "as is" without
  5. # warranty of any kind, either expressed or implied, including, but not limited to,
  6. # the implied warranties of merchantability and fitness for a particular purpose.
  7. # The entire risk as to the quality and performance of the software is with you.
  8. # Should the software prove defective, you assume the cost of all necessary
  9. # servicing, repair, or correction.
  10. # In no event unless required by applicable law or agreed to in writing will any
  11. # copyright holder, or any other party who may modify and/or redistribute the software
  12. # as permitted by the above licence, be liable to you for damages, including any general,
  13. # special, incidental, or consequential damages arising out of the use or inability
  14. # to use the software (including but not limited to loss of data or data being rendered
  15. # inaccurate or losses sustained by you or third parties or a failure of the software
  16. # to operate with any other software), even if such holder or other party
  17. # has been advised of the possibility of such damages.
  18. # AUTHOR
  19. # John McNamara jmcnamara@cpan.org
  20. # COPYRIGHT
  21. # Copyright MM-MMX, John McNamara.
  22. # All Rights Reserved. This module is free software. It may be used,
  23. # redistributed and/or modified under the terms of
  24. # the Artistic License(full text of the Artistic License http://dev.perl.org/licenses/artistic.html).
  25. package Spreadsheet::WriteExcel::Chart::Area;
  26. ###############################################################################
  27. #
  28. # Area - A writer class for Excel Area charts.
  29. #
  30. # Used in conjunction with Spreadsheet::WriteExcel::Chart.
  31. #
  32. # See formatting note in Spreadsheet::WriteExcel::Chart.
  33. #
  34. # Copyright 2000-2010, John McNamara, jmcnamara@cpan.org
  35. #
  36. # Documentation after __END__
  37. #
  38. require Exporter;
  39. use strict;
  40. use Spreadsheet::WriteExcel::Chart;
  41. use vars qw($VERSION @ISA);
  42. @ISA = qw(Spreadsheet::WriteExcel::Chart Exporter);
  43. $VERSION = '2.37';
  44. ###############################################################################
  45. #
  46. # new()
  47. #
  48. #
  49. sub new {
  50. my $class = shift;
  51. my $self = Spreadsheet::WriteExcel::Chart->new( @_ );
  52. bless $self, $class;
  53. return $self;
  54. }
  55. ###############################################################################
  56. #
  57. # _store_chart_type()
  58. #
  59. # Implementation of the abstract method from the specific chart class.
  60. #
  61. # Write the AREA chart BIFF record. Defines a area chart type.
  62. #
  63. sub _store_chart_type {
  64. my $self = shift;
  65. my $record = 0x101A; # Record identifier.
  66. my $length = 0x0002; # Number of bytes to follow.
  67. my $grbit = 0x0001; # Option flags.
  68. my $header = pack 'vv', $record, $length;
  69. my $data = pack 'v', $grbit;
  70. $self->_append( $header, $data );
  71. }
  72. 1;
  73. __END__
  74. =head1 NAME
  75. Area - A writer class for Excel Area charts.
  76. =head1 SYNOPSIS
  77. To create a simple Excel file with a Area chart using Spreadsheet::WriteExcel:
  78. #!/usr/bin/perl -w
  79. use strict;
  80. use Spreadsheet::WriteExcel;
  81. my $workbook = Spreadsheet::WriteExcel->new( 'chart.xls' );
  82. my $worksheet = $workbook->add_worksheet();
  83. my $chart = $workbook->add_chart( type => 'area' );
  84. # Configure the chart.
  85. $chart->add_series(
  86. categories => '=Sheet1!$A$2:$A$7',
  87. values => '=Sheet1!$B$2:$B$7',
  88. );
  89. # Add the worksheet data the chart refers to.
  90. my $data = [
  91. [ 'Category', 2, 3, 4, 5, 6, 7 ],
  92. [ 'Value', 1, 4, 5, 2, 1, 5 ],
  93. ];
  94. $worksheet->write( 'A1', $data );
  95. __END__
  96. =head1 DESCRIPTION
  97. This module implements Area charts for L<Spreadsheet::WriteExcel>. The chart object is created via the Workbook C<add_chart()> method:
  98. my $chart = $workbook->add_chart( type => 'area' );
  99. Once the object is created it can be configured via the following methods that are common to all chart classes:
  100. $chart->add_series();
  101. $chart->set_x_axis();
  102. $chart->set_y_axis();
  103. $chart->set_title();
  104. These methods are explained in detail in L<Spreadsheet::WriteExcel::Chart>. Class specific methods or settings, if any, are explained below.
  105. =head1 Area Chart Methods
  106. There aren't currently any area chart specific methods. See the TODO section of L<Spreadsheet::WriteExcel::Chart>.
  107. =head1 EXAMPLE
  108. Here is a complete example that demonstrates most of the available features when creating a chart.
  109. #!/usr/bin/perl -w
  110. use strict;
  111. use Spreadsheet::WriteExcel;
  112. my $workbook = Spreadsheet::WriteExcel->new( 'chart_area.xls' );
  113. my $worksheet = $workbook->add_worksheet();
  114. my $bold = $workbook->add_format( bold => 1 );
  115. # Add the worksheet data that the charts will refer to.
  116. my $headings = [ 'Number', 'Sample 1', 'Sample 2' ];
  117. my $data = [
  118. [ 2, 3, 4, 5, 6, 7 ],
  119. [ 1, 4, 5, 2, 1, 5 ],
  120. [ 3, 6, 7, 5, 4, 3 ],
  121. ];
  122. $worksheet->write( 'A1', $headings, $bold );
  123. $worksheet->write( 'A2', $data );
  124. # Create a new chart object. In this case an embedded chart.
  125. my $chart = $workbook->add_chart( type => 'area', embedded => 1 );
  126. # Configure the first series. (Sample 1)
  127. $chart->add_series(
  128. name => 'Sample 1',
  129. categories => '=Sheet1!$A$2:$A$7',
  130. values => '=Sheet1!$B$2:$B$7',
  131. );
  132. # Configure the second series. (Sample 2)
  133. $chart->add_series(
  134. name => 'Sample 2',
  135. categories => '=Sheet1!$A$2:$A$7',
  136. values => '=Sheet1!$C$2:$C$7',
  137. );
  138. # Add a chart title and some axis labels.
  139. $chart->set_title ( name => 'Results of sample analysis' );
  140. $chart->set_x_axis( name => 'Test number' );
  141. $chart->set_y_axis( name => 'Sample length (cm)' );
  142. # Insert the chart into the worksheet (with an offset).
  143. $worksheet->insert_chart( 'D2', $chart, 25, 10 );
  144. __END__
  145. =begin html
  146. <p>This will produce a chart that looks like this:</p>
  147. <p><center><img src="http://homepage.eircom.net/~jmcnamara/perl/images/area1.jpg" width="527" height="320" alt="Chart example." /></center></p>
  148. =end html
  149. =head1 AUTHOR
  150. John McNamara jmcnamara@cpan.org
  151. =head1 COPYRIGHT
  152. Copyright MM-MMX, John McNamara.
  153. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.