.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Excel::Writer::XLSX::Chart 3pm" .TH Excel::Writer::XLSX::Chart 3pm "2023-04-12" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Chart \- A class for writing Excel Charts. .SH "SYNOPSIS" .IX Header "SYNOPSIS" To create a simple Excel file with a chart using Excel::Writer::XLSX: .PP .Vb 1 \& #!/usr/bin/perl \& \& use strict; \& use warnings; \& use Excel::Writer::XLSX; \& \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqchart.xlsx\*(Aq ); \& my $worksheet = $workbook\->add_worksheet(); \& \& # Add the worksheet data the chart refers to. \& my $data = [ \& [ \*(AqCategory\*(Aq, 2, 3, 4, 5, 6, 7 ], \& [ \*(AqValue\*(Aq, 1, 4, 5, 2, 1, 5 ], \& \& ]; \& \& $worksheet\->write( \*(AqA1\*(Aq, $data ); \& \& # Add a worksheet chart. \& my $chart = $workbook\->add_chart( type => \*(Aqcolumn\*(Aq ); \& \& # Configure the chart. \& $chart\->add_series( \& categories => \*(Aq=Sheet1!$A$2:$A$7\*(Aq, \& values => \*(Aq=Sheet1!$B$2:$B$7\*(Aq, \& ); \& \& $workbook\->close(); \& \& _\|_END_\|_ .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The \f(CW\*(C`Chart\*(C'\fR module is an abstract base class for modules that implement charts in Excel::Writer::XLSX. The information below is applicable to all of the available subclasses. .PP The \f(CW\*(C`Chart\*(C'\fR module isn't used directly. A chart object is created via the Workbook \f(CW\*(C`add_chart()\*(C'\fR method where the chart type is specified: .PP .Vb 1 \& my $chart = $workbook\->add_chart( type => \*(Aqcolumn\*(Aq ); .Ve .PP Currently the supported chart types are: .IP "\(bu" 4 \&\f(CW\*(C`area\*(C'\fR .Sp Creates an Area (filled line) style chart. See Excel::Writer::XLSX::Chart::Area. .IP "\(bu" 4 \&\f(CW\*(C`bar\*(C'\fR .Sp Creates a Bar style (transposed histogram) chart. See Excel::Writer::XLSX::Chart::Bar. .IP "\(bu" 4 \&\f(CW\*(C`column\*(C'\fR .Sp Creates a column style (histogram) chart. See Excel::Writer::XLSX::Chart::Column. .IP "\(bu" 4 \&\f(CW\*(C`line\*(C'\fR .Sp Creates a Line style chart. See Excel::Writer::XLSX::Chart::Line. .IP "\(bu" 4 \&\f(CW\*(C`pie\*(C'\fR .Sp Creates a Pie style chart. See Excel::Writer::XLSX::Chart::Pie. .IP "\(bu" 4 \&\f(CW\*(C`doughnut\*(C'\fR .Sp Creates a Doughnut style chart. See Excel::Writer::XLSX::Chart::Doughnut. .IP "\(bu" 4 \&\f(CW\*(C`scatter\*(C'\fR .Sp Creates a Scatter style chart. See Excel::Writer::XLSX::Chart::Scatter. .IP "\(bu" 4 \&\f(CW\*(C`stock\*(C'\fR .Sp Creates a Stock style chart. See Excel::Writer::XLSX::Chart::Stock. .IP "\(bu" 4 \&\f(CW\*(C`radar\*(C'\fR .Sp Creates a Radar style chart. See Excel::Writer::XLSX::Chart::Radar. .PP Chart subtypes are also supported in some cases: .PP .Vb 1 \& $workbook\->add_chart( type => \*(Aqbar\*(Aq, subtype => \*(Aqstacked\*(Aq ); .Ve .PP The currently available subtypes are: .PP .Vb 3 \& area \& stacked \& percent_stacked \& \& bar \& stacked \& percent_stacked \& \& column \& stacked \& percent_stacked \& \& scatter \& straight_with_markers \& straight \& smooth_with_markers \& smooth \& \& line \& stacked \& percent_stacked \& \& radar \& with_markers \& filled .Ve .SH "CHART METHODS" .IX Header "CHART METHODS" Methods that are common to all chart types are documented below. See the documentation for each of the above chart modules for chart specific information. .SS "\fBadd_series()\fP" .IX Subsection "add_series()" In an Excel chart a \*(L"series\*(R" is a collection of information such as values, X axis labels and the formatting that define which data is plotted. .PP With an Excel::Writer::XLSX chart object the \f(CW\*(C`add_series()\*(C'\fR method is used to set the properties for a series: .PP .Vb 5 \& $chart\->add_series( \& categories => \*(Aq=Sheet1!$A$2:$A$10\*(Aq, # Optional. \& values => \*(Aq=Sheet1!$B$2:$B$10\*(Aq, # Required. \& line => { color => \*(Aqblue\*(Aq }, \& ); .Ve .PP The properties that can be set are: .IP "\(bu" 4 \&\f(CW\*(C`values\*(C'\fR .Sp This is the most important property of a series and must be set for every chart object. It links the chart with the worksheet data that it displays. A formula or array ref can be used for the data range, see below. .IP "\(bu" 4 \&\f(CW\*(C`categories\*(C'\fR .Sp This sets the chart category labels. The category is more or less the same as the X axis. In most chart types the \f(CW\*(C`categories\*(C'\fR property is optional and the chart will just assume a sequential series from \f(CW\*(C`1 .. n\*(C'\fR. .IP "\(bu" 4 \&\f(CW\*(C`name\*(C'\fR .Sp Set the name for the series. The name is displayed in the chart legend and in the formula bar. The name property is optional and if it isn't supplied it will default to \f(CW\*(C`Series 1 .. n\*(C'\fR. .IP "\(bu" 4 \&\f(CW\*(C`line\*(C'\fR .Sp Set the properties of the series line type such as colour and width. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`border\*(C'\fR .Sp Set the border properties of the series such as colour and style. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`fill\*(C'\fR .Sp Set the fill properties of the series such as colour. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`pattern\*(C'\fR .Sp Set the pattern properties of the series. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`gradient\*(C'\fR .Sp Set the gradient properties of the series. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`marker\*(C'\fR .Sp Set the properties of the series marker such as style and colour. See the \*(L"\s-1SERIES OPTIONS\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`trendline\*(C'\fR .Sp Set the properties of the series trendline such as linear, polynomial and moving average types. See the \*(L"\s-1SERIES OPTIONS\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`smooth\*(C'\fR .Sp The \f(CW\*(C`smooth\*(C'\fR option is used to set the smooth property of a line series. See the \*(L"\s-1SERIES OPTIONS\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`y_error_bars\*(C'\fR .Sp Set vertical error bounds for a chart series. See the \*(L"\s-1SERIES OPTIONS\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`x_error_bars\*(C'\fR .Sp Set horizontal error bounds for a chart series. See the \*(L"\s-1SERIES OPTIONS\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`data_labels\*(C'\fR .Sp Set data labels for the series. See the \*(L"\s-1SERIES OPTIONS\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`points\*(C'\fR .Sp Set properties for individual points in a series. See the \*(L"\s-1SERIES OPTIONS\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`invert_if_negative\*(C'\fR .Sp Invert the fill colour for negative values. Usually only applicable to column and bar charts. .IP "\(bu" 4 \&\f(CW\*(C`overlap\*(C'\fR .Sp Set the overlap between series in a Bar/Column chart. The range is +/\- 100. Default is 0. .Sp .Vb 1 \& overlap => 20, .Ve .Sp Note, it is only necessary to apply this property to one series of the chart. .IP "\(bu" 4 \&\f(CW\*(C`gap\*(C'\fR .Sp Set the gap between series in a Bar/Column chart. The range is 0 to 500. Default is 150. .Sp .Vb 1 \& gap => 200, .Ve .Sp Note, it is only necessary to apply this property to one series of the chart. .PP The \f(CW\*(C`categories\*(C'\fR and \f(CW\*(C`values\*(C'\fR can take either a range formula such as \f(CW\*(C`=Sheet1!$A$2:$A$7\*(C'\fR or, more usefully when generating the range programmatically, an array ref with zero indexed row/column values: .PP .Vb 1 \& [ $sheetname, $row_start, $row_end, $col_start, $col_end ] .Ve .PP The following are equivalent: .PP .Vb 2 \& $chart\->add_series( categories => \*(Aq=Sheet1!$A$2:$A$7\*(Aq ); # Same as ... \& $chart\->add_series( categories => [ \*(AqSheet1\*(Aq, 1, 6, 0, 0 ] ); # Zero\-indexed. .Ve .PP You can add more than one series to a chart. In fact, some chart types such as \f(CW\*(C`stock\*(C'\fR require it. The series numbering and order in the Excel chart will be the same as the order in which they are added in Excel::Writer::XLSX. .PP .Vb 6 \& # Add the first series. \& $chart\->add_series( \& categories => \*(Aq=Sheet1!$A$2:$A$7\*(Aq, \& values => \*(Aq=Sheet1!$B$2:$B$7\*(Aq, \& name => \*(AqTest data series 1\*(Aq, \& ); \& \& # Add another series. Same categories. Different range values. \& $chart\->add_series( \& categories => \*(Aq=Sheet1!$A$2:$A$7\*(Aq, \& values => \*(Aq=Sheet1!$C$2:$C$7\*(Aq, \& name => \*(AqTest data series 2\*(Aq, \& ); .Ve .PP It is also possible to specify non-contiguous ranges: .PP .Vb 4 \& $chart\->add_series( \& categories => \*(Aq=(Sheet1!$A$1:$A$9,Sheet1!$A$14:$A$25)\*(Aq, \& values => \*(Aq=(Sheet1!$B$1:$B$9,Sheet1!$B$14:$B$25)\*(Aq, \& ); .Ve .SS "\fBset_x_axis()\fP" .IX Subsection "set_x_axis()" The \f(CW\*(C`set_x_axis()\*(C'\fR method is used to set properties of the X axis. .PP .Vb 1 \& $chart\->set_x_axis( name => \*(AqQuarterly results\*(Aq ); .Ve .PP The properties that can be set are: .PP .Vb 10 \& name \& name_font \& name_layout \& num_font \& num_format \& line \& fill \& pattern \& gradient \& min \& max \& minor_unit \& major_unit \& interval_unit \& interval_tick \& crossing \& reverse \& position_axis \& log_base \& label_position \& major_gridlines \& minor_gridlines \& visible \& date_axis \& text_axis \& minor_unit_type \& major_unit_type \& minor_tick_mark \& major_tick_mark \& display_units \& display_units_visible .Ve .PP These are explained below. Some properties are only applicable to value or category axes, as indicated. See \*(L"Value and Category Axes\*(R" for an explanation of Excel's distinction between the axis types. .IP "\(bu" 4 \&\f(CW\*(C`name\*(C'\fR .Sp Set the name (title or caption) for the axis. The name is displayed below the X axis. The \f(CW\*(C`name\*(C'\fR property is optional. The default is to have no axis name. (Applicable to category and value axes). .Sp .Vb 1 \& $chart\->set_x_axis( name => \*(AqQuarterly results\*(Aq ); .Ve .Sp The name can also be a formula such as \f(CW\*(C`=Sheet1!$A$1\*(C'\fR. .IP "\(bu" 4 \&\f(CW\*(C`name_font\*(C'\fR .Sp Set the font properties for the axis title. (Applicable to category and value axes). .Sp .Vb 1 \& $chart\->set_x_axis( name_font => { name => \*(AqArial\*(Aq, size => 10 } ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`name_layout\*(C'\fR .Sp Set the \f(CW\*(C`(x, y)\*(C'\fR position of the axis caption in chart relative units. (Applicable to category and value axes). .Sp .Vb 7 \& $chart\->set_x_axis( \& name => \*(AqX axis\*(Aq, \& name_layout => { \& x => 0.34, \& y => 0.85, \& } \& ); .Ve .Sp See the \*(L"\s-1CHART LAYOUT\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`num_font\*(C'\fR .Sp Set the font properties for the axis numbers. (Applicable to category and value axes). .Sp .Vb 1 \& $chart\->set_x_axis( num_font => { bold => 1, italic => 1 } ); .Ve .Sp See the \*(L"\s-1CHART FONTS\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`num_format\*(C'\fR .Sp Set the number format for the axis. (Applicable to category and value axes). .Sp .Vb 2 \& $chart\->set_x_axis( num_format => \*(Aq#,##0.00\*(Aq ); \& $chart\->set_y_axis( num_format => \*(Aq0.00%\*(Aq ); .Ve .Sp The number format is similar to the Worksheet Cell Format \f(CW\*(C`num_format\*(C'\fR apart from the fact that a format index cannot be used. The explicit format string must be used as shown above. See \*(L"\fBset_num_format()\fR\*(R" in Excel::Writer::XLSX for more information. .IP "\(bu" 4 \&\f(CW\*(C`line\*(C'\fR .Sp Set the properties of the axis line type such as colour and width. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .Sp .Vb 1 \& $chart\->set_x_axis( line => { none => 1 }); .Ve .IP "\(bu" 4 \&\f(CW\*(C`fill\*(C'\fR .Sp Set the fill properties of the axis such as colour. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. Note, in Excel the axis fill is applied to the area of the numbers of the axis and not to the area of the axis bounding box. That background is set from the chartarea fill. .IP "\(bu" 4 \&\f(CW\*(C`pattern\*(C'\fR .Sp Set the pattern properties of the axis such as colour. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`gradient\*(C'\fR .Sp Set the gradient properties of the axis such as colour. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`min\*(C'\fR .Sp Set the minimum value for the axis range. (Applicable to value axes only.) .Sp .Vb 1 \& $chart\->set_x_axis( min => 20 ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`max\*(C'\fR .Sp Set the maximum value for the axis range. (Applicable to value axes only.) .Sp .Vb 1 \& $chart\->set_x_axis( max => 80 ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`minor_unit\*(C'\fR .Sp Set the increment of the minor units in the axis range. (Applicable to value axes only.) .Sp .Vb 1 \& $chart\->set_x_axis( minor_unit => 0.4 ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`major_unit\*(C'\fR .Sp Set the increment of the major units in the axis range. (Applicable to value axes only.) .Sp .Vb 1 \& $chart\->set_x_axis( major_unit => 2 ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`interval_unit\*(C'\fR .Sp Set the interval unit for a category axis. (Applicable to category axes only.) .Sp .Vb 1 \& $chart\->set_x_axis( interval_unit => 2 ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`interval_tick\*(C'\fR .Sp Set the tick interval for a category axis. (Applicable to category axes only.) .Sp .Vb 1 \& $chart\->set_x_axis( interval_tick => 4 ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`crossing\*(C'\fR .Sp Set the position where the y axis will cross the x axis. (Applicable to category and value axes.) .Sp The \f(CW\*(C`crossing\*(C'\fR value can either be a numeric value or the strings \f(CW\*(Aqmax\*(Aq\fR or \f(CW\*(Aqmin\*(Aq\fR to set the crossing at the maximum/minimum axis value. .Sp .Vb 3 \& $chart\->set_x_axis( crossing => 3 ); \& # or \& $chart\->set_x_axis( crossing => \*(Aqmax\*(Aq ); .Ve .Sp \&\fBFor category axes the numeric value must be an integer\fR to represent the category number that the axis crosses at. For value axes it can have any value associated with the axis. .Sp If crossing is omitted (the default) the crossing will be set automatically by Excel based on the chart data. .IP "\(bu" 4 \&\f(CW\*(C`position_axis\*(C'\fR .Sp Position the axis on or between the axis tick marks. (Applicable to category axes only.) .Sp There are two allowable values \f(CW\*(C`on_tick\*(C'\fR and \f(CW\*(C`between\*(C'\fR: .Sp .Vb 2 \& $chart\->set_x_axis( position_axis => \*(Aqon_tick\*(Aq ); \& $chart\->set_x_axis( position_axis => \*(Aqbetween\*(Aq ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`reverse\*(C'\fR .Sp Reverse the order of the axis categories or values. (Applicable to category and value axes.) .Sp .Vb 1 \& $chart\->set_x_axis( reverse => 1 ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`log_base\*(C'\fR .Sp Set the log base of the axis range. (Applicable to value axes only.) .Sp .Vb 1 \& $chart\->set_x_axis( log_base => 10 ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`label_position\*(C'\fR .Sp Set the \*(L"Axis labels\*(R" position for the axis. The following positions are available: .Sp .Vb 4 \& next_to (the default) \& high \& low \& none .Ve .IP "\(bu" 4 \&\f(CW\*(C`major_gridlines\*(C'\fR .Sp Configure the major gridlines for the axis. The available properties are: .Sp .Vb 2 \& visible \& line .Ve .Sp For example: .Sp .Vb 6 \& $chart\->set_x_axis( \& major_gridlines => { \& visible => 1, \& line => { color => \*(Aqred\*(Aq, width => 1.25, dash_type => \*(Aqdash\*(Aq } \& } \& ); .Ve .Sp The \f(CW\*(C`visible\*(C'\fR property is usually on for the X\-axis but it depends on the type of chart. .Sp The \f(CW\*(C`line\*(C'\fR property sets the gridline properties such as colour and width. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`minor_gridlines\*(C'\fR .Sp This takes the same options as \f(CW\*(C`major_gridlines\*(C'\fR above. .Sp The minor gridline \f(CW\*(C`visible\*(C'\fR property is off by default for all chart types. .IP "\(bu" 4 \&\f(CW\*(C`visible\*(C'\fR .Sp Configure the visibility of the axis. .Sp .Vb 1 \& $chart\->set_x_axis( visible => 0 ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`date_axis\*(C'\fR .Sp This option is used to treat a category axis with date or time data as a Date Axis. (Applicable to category axes only.) .Sp .Vb 1 \& $chart\->set_x_axis( date_axis => 1 ); .Ve .Sp This option also allows you to set \f(CW\*(C`max\*(C'\fR and \f(CW\*(C`min\*(C'\fR values for a category axis which isn't allowed by Excel for non-date category axes. .Sp See \*(L"Date Category Axes\*(R" for more details. .IP "\(bu" 4 \&\f(CW\*(C`text_axis\*(C'\fR .Sp This option is used to treat a category axis explicitly as a Text Axis. (Applicable to category axes only.) .Sp .Vb 1 \& $chart\->set_x_axis( text_axis => 1 ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`minor_unit_type\*(C'\fR .Sp For \f(CW\*(C`date_axis\*(C'\fR axes, see above, this option is used to set the type of the minor units. (Applicable to date category axes only.) .Sp .Vb 5 \& $chart\->set_x_axis( \& date_axis => 1, \& minor_unit => 4, \& minor_unit_type => \*(Aqmonths\*(Aq, \& ); .Ve .Sp The allowable values for this option are \f(CW\*(C`days\*(C'\fR, \f(CW\*(C`months\*(C'\fR and \f(CW\*(C`years\*(C'\fR. .IP "\(bu" 4 \&\f(CW\*(C`major_unit_type\*(C'\fR .Sp Same as \f(CW\*(C`minor_unit_type\*(C'\fR, see above, but for major axes unit types. .Sp More than one property can be set in a call to \f(CW\*(C`set_x_axis()\*(C'\fR: .Sp .Vb 5 \& $chart\->set_x_axis( \& name => \*(AqQuarterly results\*(Aq, \& min => 10, \& max => 80, \& ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`major_tick_mark\*(C'\fR .Sp Set the axis major tick mark type to one of the following values: .Sp .Vb 4 \& none \& inside \& outside \& cross (inside and outside) .Ve .Sp For example: .Sp .Vb 2 \& $chart\->set_x_axis( major_tick_mark => \*(Aqnone\*(Aq, \& minor_tick_mark => \*(Aqinside\*(Aq ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`minor_tick_mark\*(C'\fR .Sp Set the axis minor tick mark type. Same as \f(CW\*(C`major_tick_mark\*(C'\fR, see above. .IP "\(bu" 4 \&\f(CW\*(C`display_units\*(C'\fR .Sp Set the display units for the axis. This can be useful if the axis numbers are very large but you don't want to represent them in scientific notation. (Applicable to value axes only.) The available display units are: .Sp .Vb 9 \& hundreds \& thousands \& ten_thousands \& hundred_thousands \& millions \& ten_millions \& hundred_millions \& billions \& trillions .Ve .Sp Example: .Sp .Vb 2 \& $chart\->set_x_axis( display_units => \*(Aqthousands\*(Aq ) \& $chart\->set_y_axis( display_units => \*(Aqmillions\*(Aq ) .Ve .Sp * \f(CW\*(C`display_units_visible\*(C'\fR .Sp Control the visibility of the display units turned on by the previous option. This option is on by default. (Applicable to value axes only.):: .Sp .Vb 2 \& $chart\->set_x_axis( display_units => \*(Aqthousands\*(Aq, \& display_units_visible => 0 ) .Ve .SS "\fBset_y_axis()\fP" .IX Subsection "set_y_axis()" The \f(CW\*(C`set_y_axis()\*(C'\fR method is used to set properties of the Y axis. The properties that can be set are the same as for \f(CW\*(C`set_x_axis\*(C'\fR, see above. .SS "\fBset_x2_axis()\fP" .IX Subsection "set_x2_axis()" The \f(CW\*(C`set_x2_axis()\*(C'\fR method is used to set properties of the secondary X axis. The properties that can be set are the same as for \f(CW\*(C`set_x_axis\*(C'\fR, see above. The default properties for this axis are: .PP .Vb 3 \& label_position => \*(Aqnone\*(Aq, \& crossing => \*(Aqmax\*(Aq, \& visible => 0, .Ve .SS "\fBset_y2_axis()\fP" .IX Subsection "set_y2_axis()" The \f(CW\*(C`set_y2_axis()\*(C'\fR method is used to set properties of the secondary Y axis. The properties that can be set are the same as for \f(CW\*(C`set_x_axis\*(C'\fR, see above. The default properties for this axis are: .PP .Vb 1 \& major_gridlines => { visible => 0 } .Ve .SS "\fBcombine()\fP" .IX Subsection "combine()" The chart \f(CW\*(C`combine()\*(C'\fR method is used to combine two charts of different types, for example a column and line chart: .PP .Vb 1 \& my $column_chart = $workbook\->add_chart( type => \*(Aqcolumn\*(Aq, embedded => 1 ); \& \& # Configure the data series for the primary chart. \& $column_chart\->add_series(...); \& \& # Create a new column chart. This will use this as the secondary chart. \& my $line_chart = $workbook\->add_chart( type => \*(Aqline\*(Aq, embedded => 1 ); \& \& # Configure the data series for the secondary chart. \& $line_chart\->add_series(...); \& \& # Combine the charts. \& $column_chart\->combine( $line_chart ); .Ve .PP See \*(L"Combined Charts\*(R" for more details. .SS "\fBset_size()\fP" .IX Subsection "set_size()" The \f(CW\*(C`set_size()\*(C'\fR method is used to set the dimensions of the chart. The size properties that can be set are: .PP .Vb 6 \& width \& height \& x_scale \& y_scale \& x_offset \& y_offset .Ve .PP The \f(CW\*(C`width\*(C'\fR and \f(CW\*(C`height\*(C'\fR are in pixels. The default chart width is 480 pixels and the default height is 288 pixels. The size of the chart can be modified by setting the \f(CW\*(C`width\*(C'\fR and \f(CW\*(C`height\*(C'\fR or by setting the \f(CW\*(C`x_scale\*(C'\fR and \f(CW\*(C`y_scale\*(C'\fR: .PP .Vb 1 \& $chart\->set_size( width => 720, height => 576 ); \& \& # Same as: \& \& $chart\->set_size( x_scale => 1.5, y_scale => 2 ); .Ve .PP The \f(CW\*(C`x_offset\*(C'\fR and \f(CW\*(C`y_offset\*(C'\fR position the top left corner of the chart in the cell that it is inserted into. .PP Note: the \f(CW\*(C`x_scale\*(C'\fR, \f(CW\*(C`y_scale\*(C'\fR, \f(CW\*(C`x_offset\*(C'\fR and \f(CW\*(C`y_offset\*(C'\fR parameters can also be set via the \f(CW\*(C`insert_chart()\*(C'\fR method: .PP .Vb 2 \& $worksheet\->insert_chart( \*(AqE2\*(Aq, $chart, { x_offset =>2, y_offset => 4, \& x_scale => 1.5, y_scale => 2 } ); .Ve .SS "\fBset_title()\fP" .IX Subsection "set_title()" The \f(CW\*(C`set_title()\*(C'\fR method is used to set properties of the chart title. .PP .Vb 1 \& $chart\->set_title( name => \*(AqYear End Results\*(Aq ); .Ve .PP The properties that can be set are: .IP "\(bu" 4 \&\f(CW\*(C`name\*(C'\fR .Sp Set the name (title) for the chart. The name is displayed above the chart. The name can also be a formula such as \f(CW\*(C`=Sheet1!$A$1\*(C'\fR. The name property is optional. The default is to have no chart title. .IP "\(bu" 4 \&\f(CW\*(C`name_font\*(C'\fR .Sp Set the font properties for the chart title. See the \*(L"\s-1CHART FONTS\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`overlay\*(C'\fR .Sp Allow the title to be overlaid on the chart. Generally used with the layout property below. .IP "\(bu" 4 \&\f(CW\*(C`layout\*(C'\fR .Sp Set the \f(CW\*(C`(x, y)\*(C'\fR position of the title in chart relative units: .Sp .Vb 8 \& $chart\->set_title( \& name => \*(AqTitle\*(Aq, \& overlay => 1, \& layout => { \& x => 0.42, \& y => 0.14, \& } \& ); .Ve .Sp See the \*(L"\s-1CHART LAYOUT\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`none\*(C'\fR .Sp By default Excel adds an automatic chart title to charts with a single series and a user defined series name. The \f(CW\*(C`none\*(C'\fR option turns this default title off. It also turns off all other \f(CW\*(C`set_title()\*(C'\fR options. .Sp .Vb 1 \& $chart\->set_title( none => 1 ); .Ve .SS "\fBset_legend()\fP" .IX Subsection "set_legend()" The \f(CW\*(C`set_legend()\*(C'\fR method is used to set properties of the chart legend. .PP The properties that can be set are: .IP "\(bu" 4 \&\f(CW\*(C`none\*(C'\fR .Sp The \f(CW\*(C`none\*(C'\fR option turns off the chart legend. In Excel chart legends are on by default: .Sp .Vb 1 \& $chart\->set_legend( none => 1 ); .Ve .Sp Note, for backward compatibility, it is also possible to turn off the legend via the \f(CW\*(C`position\*(C'\fR property: .Sp .Vb 1 \& $chart\->set_legend( position => \*(Aqnone\*(Aq ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`position\*(C'\fR .Sp Set the position of the chart legend. .Sp .Vb 1 \& $chart\->set_legend( position => \*(Aqbottom\*(Aq ); .Ve .Sp The default legend position is \f(CW\*(C`right\*(C'\fR. The available positions are: .Sp .Vb 9 \& top \& bottom \& left \& right \& top_right \& overlay_left \& overlay_right \& overlay_top_right \& none .Ve .IP "\(bu" 4 \&\f(CW\*(C`border\*(C'\fR .Sp Set the border properties of the legend such as colour and style. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`fill\*(C'\fR .Sp Set the fill properties of the legend such as colour. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`pattern\*(C'\fR .Sp Set the pattern fill properties of the legend. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`gradient\*(C'\fR .Sp Set the gradient fill properties of the legend. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`font\*(C'\fR .Sp Set the font properties of the chart legend: .Sp .Vb 1 \& $chart\->set_legend( font => { bold => 1, italic => 1 } ); .Ve .Sp See the \*(L"\s-1CHART FONTS\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`delete_series\*(C'\fR .Sp This allows you to remove 1 or more series from the legend (the series will still display on the chart). This property takes an array ref as an argument and the series are zero indexed: .Sp .Vb 2 \& # Delete/hide series index 0 and 2 from the legend. \& $chart\->set_legend( delete_series => [0, 2] ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`layout\*(C'\fR .Sp Set the \f(CW\*(C`(x, y)\*(C'\fR position of the legend in chart relative units: .Sp .Vb 8 \& $chart\->set_legend( \& layout => { \& x => 0.80, \& y => 0.37, \& width => 0.12, \& height => 0.25, \& } \& ); .Ve .Sp See the \*(L"\s-1CHART LAYOUT\*(R"\s0 section below. .SS "\fBset_chartarea()\fP" .IX Subsection "set_chartarea()" The \f(CW\*(C`set_chartarea()\*(C'\fR method is used to set the properties of the chart area. .PP .Vb 4 \& $chart\->set_chartarea( \& border => { none => 1 }, \& fill => { color => \*(Aqred\*(Aq } \& ); .Ve .PP The properties that can be set are: .IP "\(bu" 4 \&\f(CW\*(C`border\*(C'\fR .Sp Set the border properties of the chartarea such as colour and style. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`fill\*(C'\fR .Sp Set the fill properties of the chartarea such as colour. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`pattern\*(C'\fR .Sp Set the pattern fill properties of the chartarea. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`gradient\*(C'\fR .Sp Set the gradient fill properties of the chartarea. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .SS "\fBset_plotarea()\fP" .IX Subsection "set_plotarea()" The \f(CW\*(C`set_plotarea()\*(C'\fR method is used to set properties of the plot area of a chart. .PP .Vb 4 \& $chart\->set_plotarea( \& border => { color => \*(Aqyellow\*(Aq, width => 1, dash_type => \*(Aqdash\*(Aq }, \& fill => { color => \*(Aq#92D050\*(Aq } \& ); .Ve .PP The properties that can be set are: .IP "\(bu" 4 \&\f(CW\*(C`border\*(C'\fR .Sp Set the border properties of the plotarea such as colour and style. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`fill\*(C'\fR .Sp Set the fill properties of the plotarea such as colour. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`pattern\*(C'\fR .Sp Set the pattern fill properties of the plotarea. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`gradient\*(C'\fR .Sp Set the gradient fill properties of the plotarea. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .IP "\(bu" 4 \&\f(CW\*(C`layout\*(C'\fR .Sp Set the \f(CW\*(C`(x, y)\*(C'\fR position of the plotarea in chart relative units: .Sp .Vb 8 \& $chart\->set_plotarea( \& layout => { \& x => 0.35, \& y => 0.26, \& width => 0.62, \& height => 0.50, \& } \& ); .Ve .Sp See the \*(L"\s-1CHART LAYOUT\*(R"\s0 section below. .SS "\fBset_style()\fP" .IX Subsection "set_style()" The \f(CW\*(C`set_style()\*(C'\fR method is used to set the style of the chart to one of the 42 built-in styles available on the 'Design' tab in Excel: .PP .Vb 1 \& $chart\->set_style( 4 ); .Ve .PP The default style is 2. .SS "\fBset_table()\fP" .IX Subsection "set_table()" The \f(CW\*(C`set_table()\*(C'\fR method adds a data table below the horizontal axis with the data used to plot the chart. .PP .Vb 1 \& $chart\->set_table(); .Ve .PP The available options, with default values are: .PP .Vb 5 \& vertical => 1 # Display vertical lines in the table. \& horizontal => 1 # Display horizontal lines in the table. \& outline => 1 # Display an outline in the table. \& show_keys => 0 # Show the legend keys with the table data. \& font => {} # Standard chart font properties. .Ve .PP The data table can only be shown with Bar, Column, Line, Area and stock charts. For font properties see the \*(L"\s-1CHART FONTS\*(R"\s0 section below. .SS "set_up_down_bars" .IX Subsection "set_up_down_bars" The \f(CW\*(C`set_up_down_bars()\*(C'\fR method adds Up-Down bars to Line charts to indicate the difference between the first and last data series. .PP .Vb 1 \& $chart\->set_up_down_bars(); .Ve .PP It is possible to format the up and down bars to add \f(CW\*(C`fill\*(C'\fR, \f(CW\*(C`pattern\*(C'\fR, \f(CW\*(C`gradient\*(C'\fR and \f(CW\*(C`border\*(C'\fR properties if required. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .PP .Vb 4 \& $chart\->set_up_down_bars( \& up => { fill => { color => \*(Aqgreen\*(Aq } }, \& down => { fill => { color => \*(Aqred\*(Aq } }, \& ); .Ve .PP Up-down bars can only be applied to Line charts and to Stock charts (by default). .SS "set_drop_lines" .IX Subsection "set_drop_lines" The \f(CW\*(C`set_drop_lines()\*(C'\fR method adds Drop Lines to charts to show the Category value of points in the data. .PP .Vb 1 \& $chart\->set_drop_lines(); .Ve .PP It is possible to format the Drop Line \f(CW\*(C`line\*(C'\fR properties if required. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .PP .Vb 1 \& $chart\->set_drop_lines( line => { color => \*(Aqred\*(Aq, dash_type => \*(Aqsquare_dot\*(Aq } ); .Ve .PP Drop Lines are only available in Line, Area and Stock charts. .SS "set_high_low_lines" .IX Subsection "set_high_low_lines" The \f(CW\*(C`set_high_low_lines()\*(C'\fR method adds High-Low lines to charts to show the maximum and minimum values of points in a Category. .PP .Vb 1 \& $chart\->set_high_low_lines(); .Ve .PP It is possible to format the High-Low Line \f(CW\*(C`line\*(C'\fR properties if required. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .PP .Vb 1 \& $chart\->set_high_low_lines( line => { color => \*(Aqred\*(Aq } ); .Ve .PP High-Low Lines are only available in Line and Stock charts. .SS "\fBshow_blanks_as()\fP" .IX Subsection "show_blanks_as()" The \f(CW\*(C`show_blanks_as()\*(C'\fR method controls how blank data is displayed in a chart. .PP .Vb 1 \& $chart\->show_blanks_as( \*(Aqspan\*(Aq ); .Ve .PP The available options are: .PP .Vb 3 \& gap # Blank data is shown as a gap. The default. \& zero # Blank data is displayed as zero. \& span # Blank data is connected with a line. .Ve .SS "\fBshow_hidden_data()\fP" .IX Subsection "show_hidden_data()" Display data in hidden rows or columns on the chart. .PP .Vb 1 \& $chart\->show_hidden_data(); .Ve .SH "SERIES OPTIONS" .IX Header "SERIES OPTIONS" This section details the following properties of \f(CW\*(C`add_series()\*(C'\fR in more detail: .PP .Vb 7 \& marker \& trendline \& y_error_bars \& x_error_bars \& data_labels \& points \& smooth .Ve .SS "Marker" .IX Subsection "Marker" The marker format specifies the properties of the markers used to distinguish series on a chart. In general only Line and Scatter chart types and trendlines use markers. .PP The following properties can be set for \f(CW\*(C`marker\*(C'\fR formats in a chart. .PP .Vb 6 \& type \& size \& border \& fill \& pattern \& gradient .Ve .PP The \f(CW\*(C`type\*(C'\fR property sets the type of marker that is used with a series. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& marker => { type => \*(Aqdiamond\*(Aq }, \& ); .Ve .PP The following \f(CW\*(C`type\*(C'\fR properties can be set for \f(CW\*(C`marker\*(C'\fR formats in a chart. These are shown in the same order as in the Excel format dialog. .PP .Vb 11 \& automatic \& none \& square \& diamond \& triangle \& x \& star \& short_dash \& long_dash \& circle \& plus .Ve .PP The \f(CW\*(C`automatic\*(C'\fR type is a special case which turns on a marker using the default marker style for the particular series number. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& marker => { type => \*(Aqautomatic\*(Aq }, \& ); .Ve .PP If \f(CW\*(C`automatic\*(C'\fR is on then other marker properties such as size, border or fill cannot be set. .PP The \f(CW\*(C`size\*(C'\fR property sets the size of the marker and is generally used in conjunction with \f(CW\*(C`type\*(C'\fR. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& marker => { type => \*(Aqdiamond\*(Aq, size => 7 }, \& ); .Ve .PP Nested \f(CW\*(C`border\*(C'\fR and \f(CW\*(C`fill\*(C'\fR properties can also be set for a marker. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .PP .Vb 9 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& marker => { \& type => \*(Aqsquare\*(Aq, \& size => 5, \& border => { color => \*(Aqred\*(Aq }, \& fill => { color => \*(Aqyellow\*(Aq }, \& }, \& ); .Ve .SS "Trendline" .IX Subsection "Trendline" A trendline can be added to a chart series to indicate trends in the data such as a moving average or a polynomial fit. .PP The following properties can be set for trendlines in a chart series. .PP .Vb 10 \& type \& order (for polynomial trends) \& period (for moving average) \& forward (for all except moving average) \& backward (for all except moving average) \& name \& line \& intercept (for exponential, linear and polynomial only) \& display_equation (for all except moving average) \& display_r_squared (for all except moving average) .Ve .PP The \f(CW\*(C`type\*(C'\fR property sets the type of trendline in the series. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& trendline => { type => \*(Aqlinear\*(Aq }, \& ); .Ve .PP The available \f(CW\*(C`trendline\*(C'\fR types are: .PP .Vb 6 \& exponential \& linear \& log \& moving_average \& polynomial \& power .Ve .PP A \f(CW\*(C`polynomial\*(C'\fR trendline can also specify the \f(CW\*(C`order\*(C'\fR of the polynomial. The default value is 2. .PP .Vb 7 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& trendline => { \& type => \*(Aqpolynomial\*(Aq, \& order => 3, \& }, \& ); .Ve .PP A \f(CW\*(C`moving_average\*(C'\fR trendline can also specify the \f(CW\*(C`period\*(C'\fR of the moving average. The default value is 2. .PP .Vb 7 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& trendline => { \& type => \*(Aqmoving_average\*(Aq, \& period => 3, \& }, \& ); .Ve .PP The \f(CW\*(C`forward\*(C'\fR and \f(CW\*(C`backward\*(C'\fR properties set the forecast period of the trendline. .PP .Vb 8 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& trendline => { \& type => \*(Aqlinear\*(Aq, \& forward => 0.5, \& backward => 0.5, \& }, \& ); .Ve .PP The \f(CW\*(C`name\*(C'\fR property sets an optional name for the trendline that will appear in the chart legend. If it isn't specified the Excel default name will be displayed. This is usually a combination of the trendline type and the series name. .PP .Vb 7 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& trendline => { \& type => \*(Aqlinear\*(Aq, \& name => \*(AqInterpolated trend\*(Aq, \& }, \& ); .Ve .PP The \f(CW\*(C`intercept\*(C'\fR property sets the point where the trendline crosses the Y (value) axis: .PP .Vb 7 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& trendline => { \& type => \*(Aqlinear\*(Aq, \& intercept => 0.8, \& }, \& ); .Ve .PP The \f(CW\*(C`display_equation\*(C'\fR property displays the trendline equation on the chart. .PP .Vb 7 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& trendline => { \& type => \*(Aqlinear\*(Aq, \& display_equation => 1, \& }, \& ); .Ve .PP The \f(CW\*(C`display_r_squared\*(C'\fR property displays the R squared value of the trendline on the chart. .PP .Vb 7 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& trendline => { \& type => \*(Aqlinear\*(Aq, \& display_r_squared => 1 \& }, \& ); .Ve .PP Several of these properties can be set in one go: .PP .Vb 10 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& trendline => { \& type => \*(Aqpolynomial\*(Aq, \& name => \*(AqMy trend name\*(Aq, \& order => 2, \& forward => 0.5, \& backward => 0.5, \& intercept => 1.5, \& display_equation => 1, \& display_r_squared => 1, \& line => { \& color => \*(Aqred\*(Aq, \& width => 1, \& dash_type => \*(Aqlong_dash\*(Aq, \& } \& }, \& ); .Ve .PP Trendlines cannot be added to series in a stacked chart or pie chart, radar chart, doughnut or (when implemented) to 3D, or surface charts. .SS "Error Bars" .IX Subsection "Error Bars" Error bars can be added to a chart series to indicate error bounds in the data. The error bars can be vertical \f(CW\*(C`y_error_bars\*(C'\fR (the most common type) or horizontal \f(CW\*(C`x_error_bars\*(C'\fR (for Bar and Scatter charts only). .PP The following properties can be set for error bars in a chart series. .PP .Vb 7 \& type \& value (for all types except standard error and custom) \& plus_values (for custom only) \& minus_values (for custom only) \& direction \& end_style \& line .Ve .PP The \f(CW\*(C`type\*(C'\fR property sets the type of error bars in the series. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& y_error_bars => { type => \*(Aqstandard_error\*(Aq }, \& ); .Ve .PP The available error bars types are available: .PP .Vb 5 \& fixed \& percentage \& standard_deviation \& standard_error \& custom .Ve .PP All error bar types, except for \f(CW\*(C`standard_error\*(C'\fR and \f(CW\*(C`custom\*(C'\fR must also have a value associated with it for the error bounds: .PP .Vb 7 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& y_error_bars => { \& type => \*(Aqpercentage\*(Aq, \& value => 5, \& }, \& ); .Ve .PP The \f(CW\*(C`custom\*(C'\fR error bar type must specify \f(CW\*(C`plus_values\*(C'\fR and \f(CW\*(C`minus_values\*(C'\fR which should either by a \f(CW\*(C`Sheet1!$A$1:$A$5\*(C'\fR type range formula or an arrayref of values: .PP .Vb 9 \& $chart\->add_series( \& categories => \*(Aq=Sheet1!$A$1:$A$5\*(Aq, \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& y_error_bars => { \& type => \*(Aqcustom\*(Aq, \& plus_values => \*(Aq=Sheet1!$C$1:$C$5\*(Aq, \& minus_values => \*(Aq=Sheet1!$D$1:$D$5\*(Aq, \& }, \& ); \& \& # or \& \& \& $chart\->add_series( \& categories => \*(Aq=Sheet1!$A$1:$A$5\*(Aq, \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& y_error_bars => { \& type => \*(Aqcustom\*(Aq, \& plus_values => [1, 1, 1, 1, 1], \& minus_values => [2, 2, 2, 2, 2], \& }, \& ); .Ve .PP Note, as in Excel the items in the \f(CW\*(C`minus_values\*(C'\fR do not need to be negative. .PP The \f(CW\*(C`direction\*(C'\fR property sets the direction of the error bars. It should be one of the following: .PP .Vb 3 \& plus # Positive direction only. \& minus # Negative direction only. \& both # Plus and minus directions, The default. .Ve .PP The \f(CW\*(C`end_style\*(C'\fR property sets the style of the error bar end cap. The options are 1 (the default) or 0 (for no end cap): .PP .Vb 9 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& y_error_bars => { \& type => \*(Aqfixed\*(Aq, \& value => 2, \& end_style => 0, \& direction => \*(Aqminus\*(Aq \& }, \& ); .Ve .SS "Data Labels" .IX Subsection "Data Labels" Data labels can be added to a chart series to indicate the values of the plotted data points. .PP The following properties can be set for \f(CW\*(C`data_labels\*(C'\fR formats in a chart. .PP .Vb 10 \& value \& category \& series_name \& position \& percentage \& leader_lines \& separator \& legend_key \& num_format \& font \& border \& fill \& pattern \& gradient \& custom .Ve .PP The \f(CW\*(C`value\*(C'\fR property turns on the \fIValue\fR data label for a series. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& data_labels => { value => 1 }, \& ); .Ve .PP The \f(CW\*(C`category\*(C'\fR property turns on the \fICategory Name\fR data label for a series. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& data_labels => { category => 1 }, \& ); .Ve .PP The \f(CW\*(C`series_name\*(C'\fR property turns on the \fISeries Name\fR data label for a series. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& data_labels => { series_name => 1 }, \& ); .Ve .PP The \f(CW\*(C`position\*(C'\fR property is used to position the data label for a series. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& data_labels => { value => 1, position => \*(Aqcenter\*(Aq }, \& ); .Ve .PP In Excel the data label positions vary for different chart types. The allowable positions are: .PP .Vb 10 \& | Position | Line | Bar | Pie | Area | \& | | Scatter | Column | Doughnut | Radar | \& | | Stock | | | | \& |\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\-\-\-| \& | center | Yes | Yes | Yes | Yes* | \& | right | Yes* | | | | \& | left | Yes | | | | \& | above | Yes | | | | \& | below | Yes | | | | \& | inside_base | | Yes | | | \& | inside_end | | Yes | Yes | | \& | outside_end | | Yes* | Yes | | \& | best_fit | | | Yes* | | .Ve .PP Note: The * indicates the default position for each chart type in Excel, if a position isn't specified. .PP The \f(CW\*(C`percentage\*(C'\fR property is used to turn on the display of data labels as a \fIPercentage\fR for a series. It is mainly used for pie and doughnut charts. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& data_labels => { percentage => 1 }, \& ); .Ve .PP The \f(CW\*(C`leader_lines\*(C'\fR property is used to turn on \fILeader Lines\fR for the data label for a series. It is mainly used for pie charts. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& data_labels => { value => 1, leader_lines => 1 }, \& ); .Ve .PP Note: Even when leader lines are turned on they aren't automatically visible in Excel or Excel::Writer::XLSX. Due to an Excel limitation (or design) leader lines only appear if the data label is moved manually or if the data labels are very close and need to be adjusted automatically. .PP The \f(CW\*(C`separator\*(C'\fR property is used to change the separator between multiple data label items: .PP .Vb 5 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& data_labels => { percentage => 1 }, \& data_labels => { value => 1, category => 1, separator => "\en" }, \& ); .Ve .PP The separator value must be one of the following strings: .PP .Vb 5 \& \*(Aq,\*(Aq \& \*(Aq;\*(Aq \& \*(Aq.\*(Aq \& "\en" \& \*(Aq \*(Aq .Ve .PP The \f(CW\*(C`legend_key\*(C'\fR property is used to turn on \fILegend Key\fR for the data label for a series: .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& data_labels => { value => 1, legend_key => 1 }, \& ); .Ve .PP The \f(CW\*(C`num_format\*(C'\fR property is used to set the number format for the data labels. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$A$1:$A$5\*(Aq, \& data_labels => { value => 1, num_format => \*(Aq#,##0.00\*(Aq }, \& ); .Ve .PP The number format is similar to the Worksheet Cell Format \f(CW\*(C`num_format\*(C'\fR apart from the fact that a format index cannot be used. The explicit format string must be used as shown above. See \*(L"\fBset_num_format()\fR\*(R" in Excel::Writer::XLSX for more information. .PP The \f(CW\*(C`font\*(C'\fR property is used to set the font properties of the data labels in a series: .PP .Vb 7 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$A$1:$A$5\*(Aq, \& data_labels => { \& value => 1, \& font => { name => \*(AqConsolas\*(Aq } \& }, \& ); .Ve .PP The \f(CW\*(C`font\*(C'\fR property is also used to rotate the data labels in a series: .PP .Vb 7 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$A$1:$A$5\*(Aq, \& data_labels => { \& value => 1, \& font => { rotation => 45 } \& }, \& ); .Ve .PP See the \*(L"\s-1CHART FONTS\*(R"\s0 section below. .PP The \f(CW\*(C`border\*(C'\fR property sets the border properties of the data labels such as colour and style. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .PP The \f(CW\*(C`fill\*(C'\fR property sets the fill properties of the data labels such as colour. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .PP Example of setting data label formatting: .PP .Vb 7 \& $chart\->add_series( \& categories => \*(Aq=Sheet1!$A$2:$A$7\*(Aq, \& values => \*(Aq=Sheet1!$B$2:$B$7\*(Aq, \& data_labels => { value => 1, \& border => {color => \*(Aqred\*(Aq}, \& fill => {color => \*(Aqyellow\*(Aq} }, \& ); .Ve .PP The \f(CW\*(C`pattern\*(C'\fR property sets the pattern properties of the data labels. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .PP The \f(CW\*(C`gradient\*(C'\fR property sets the gradient properties of the data labels. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .PP The \f(CW\*(C`custom\*(C'\fR property is used to set the properties of individual data labels, see below. .SS "Custom Data Labels" .IX Subsection "Custom Data Labels" The \f(CW\*(C`custom\*(C'\fR property data label property is used to set the properties of individual data labels in a series. The most common use for this is to set custom text or number labels: .PP .Vb 8 \& my $custom_labels = [ \& { value => \*(AqJan\*(Aq }, \& { value => \*(AqFeb\*(Aq }, \& { value => \*(AqMar\*(Aq }, \& { value => \*(AqApr\*(Aq }, \& { value => \*(AqMay\*(Aq }, \& { value => \*(AqJun\*(Aq }, \& ]; \& \& $chart\->add_series( \& categories => \*(Aq=Sheet1!$A$2:$A$7\*(Aq, \& values => \*(Aq=Sheet1!$B$2:$B$7\*(Aq, \& data_labels => { value => 1, custom => $custom_labels }, \& ); .Ve .PP As shown in the previous examples th \f(CW\*(C`custom\*(C'\fR property should be a list of dicts. Any property dict that is set to \f(CW\*(C`undef\*(C'\fR or not included in the list will be assigned the default data label value: .PP .Vb 6 \& my $custom_labels = [ \& undef, \& { value => \*(AqFeb\*(Aq }, \& { value => \*(AqMar\*(Aq }, \& { value => \*(AqApr\*(Aq }, \& ]; .Ve .PP The property elements of the \f(CW\*(C`custom\*(C'\fR lists should be dicts with the following allowable keys/sub\-properties: .PP .Vb 7 \& value \& font \& border \& fill \& pattern \& gradient \& delete .Ve .PP The \f(CW\*(C`value\*(C'\fR property should be a string, number or formula string that refers to a cell from which the value will be taken: .PP .Vb 8 \& $custom_labels = [ \& { value => \*(Aq=Sheet1!$C$2\*(Aq }, \& { value => \*(Aq=Sheet1!$C$3\*(Aq }, \& { value => \*(Aq=Sheet1!$C$4\*(Aq }, \& { value => \*(Aq=Sheet1!$C$5\*(Aq }, \& { value => \*(Aq=Sheet1!$C$6\*(Aq }, \& { value => \*(Aq=Sheet1!$C$7\*(Aq }, \& ]; .Ve .PP The \f(CW\*(C`font\*(C'\fR property is used to set the font of the custom data label of a series (See the \*(L"\s-1CHART FONTS\*(R"\s0 section below): .PP .Vb 8 \& $custom_labels = [ \& { value => \*(Aq=Sheet1!$C$1\*(Aq, font => { color => \*(Aqred\*(Aq } }, \& { value => \*(Aq=Sheet1!$C$2\*(Aq, font => { color => \*(Aqred\*(Aq } }, \& { value => \*(Aq=Sheet1!$C$2\*(Aq, font => { color => \*(Aqred\*(Aq } }, \& { value => \*(Aq=Sheet1!$C$4\*(Aq, font => { color => \*(Aqred\*(Aq } }, \& { value => \*(Aq=Sheet1!$C$5\*(Aq, font => { color => \*(Aqred\*(Aq } }, \& { value => \*(Aq=Sheet1!$C$6\*(Aq, font => { color => \*(Aqred\*(Aq } }, \& ]; .Ve .PP The \f(CW\*(C`border\*(C'\fR property sets the border properties of the data labels such as colour and style. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .PP The \f(CW\*(C`fill\*(C'\fR property sets the fill properties of the data labels such as colour. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .PP Example of setting custom data label formatting: .PP .Vb 8 \& $custom_labels = [ \& { value => \*(AqJan\*(Aq, border => {color => \*(Aqblue\*(Aq} }, \& { value => \*(AqFeb\*(Aq }, \& { value => \*(AqMar\*(Aq }, \& { value => \*(AqApr\*(Aq }, \& { value => \*(AqMay\*(Aq }, \& { value => \*(AqJun\*(Aq, fill => {color => \*(Aqgreen\*(Aq} }, \& ]; .Ve .PP The \f(CW\*(C`pattern\*(C'\fR property sets the pattern properties of the data labels. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .PP The \f(CW\*(C`gradient\*(C'\fR property sets the gradient properties of the data labels. See the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below. .PP The \f(CW\*(C`delete\*(C'\fR property can be used to delete labels in a series. This can be useful if you want to highlight one or more cells in the series, for example the maximum and the minimum: .PP .Vb 8 \& $custom_labels = [ \& undef, \& { delete => 1 }, \& { delete => 1 }, \& { delete => 1 }, \& { delete => 1 }, \& undef, \& ]; .Ve .SS "Points" .IX Subsection "Points" In general formatting is applied to an entire series in a chart. However, it is occasionally required to format individual points in a series. In particular this is required for Pie and Doughnut charts where each segment is represented by a point. .PP In these cases it is possible to use the \f(CW\*(C`points\*(C'\fR property of \f(CW\*(C`add_series()\*(C'\fR: .PP .Vb 8 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$A$1:$A$3\*(Aq, \& points => [ \& { fill => { color => \*(Aq#FF0000\*(Aq } }, \& { fill => { color => \*(Aq#CC0000\*(Aq } }, \& { fill => { color => \*(Aq#990000\*(Aq } }, \& ], \& ); .Ve .PP The \f(CW\*(C`points\*(C'\fR property takes an array ref of format options (see the \*(L"\s-1CHART FORMATTING\*(R"\s0 section below). To assign default properties to points in a series pass \f(CW\*(C`undef\*(C'\fR values in the array ref: .PP .Vb 9 \& # Format point 3 of 3 only. \& $chart\->add_series( \& values => \*(Aq=Sheet1!$A$1:$A$3\*(Aq, \& points => [ \& undef, \& undef, \& { fill => { color => \*(Aq#990000\*(Aq } }, \& ], \& ); \& \& # Format the first point only. \& $chart\->add_series( \& values => \*(Aq=Sheet1!$A$1:$A$3\*(Aq, \& points => [ { fill => { color => \*(Aq#FF0000\*(Aq } } ], \& ); .Ve .SS "Smooth" .IX Subsection "Smooth" The \f(CW\*(C`smooth\*(C'\fR option is used to set the smooth property of a line series. It is only applicable to the \f(CW\*(C`Line\*(C'\fR and \f(CW\*(C`Scatter\*(C'\fR chart types. .PP .Vb 2 \& $chart\->add_series( values => \*(Aq=Sheet1!$C$1:$C$5\*(Aq, \& smooth => 1 ); .Ve .SH "CHART FORMATTING" .IX Header "CHART FORMATTING" The following chart formatting properties can be set for any chart object that they apply to (and that are supported by Excel::Writer::XLSX) such as chart lines, column fill areas, plot area borders, markers, gridlines and other chart elements documented above. .PP .Vb 5 \& line \& border \& fill \& pattern \& gradient .Ve .PP Chart formatting properties are generally set using hash refs. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& line => { color => \*(Aqblue\*(Aq }, \& ); .Ve .PP In some cases the format properties can be nested. For example a \f(CW\*(C`marker\*(C'\fR may contain \f(CW\*(C`border\*(C'\fR and \f(CW\*(C`fill\*(C'\fR sub-properties. .PP .Vb 10 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& line => { color => \*(Aqblue\*(Aq }, \& marker => { \& type => \*(Aqsquare\*(Aq, \& size => 5, \& border => { color => \*(Aqred\*(Aq }, \& fill => { color => \*(Aqyellow\*(Aq }, \& }, \& ); .Ve .SS "Line" .IX Subsection "Line" The line format is used to specify properties of line objects that appear in a chart such as a plotted line on a chart or a border. .PP The following properties can be set for \f(CW\*(C`line\*(C'\fR formats in a chart. .PP .Vb 5 \& none \& color \& width \& dash_type \& transparency .Ve .PP The \f(CW\*(C`none\*(C'\fR property is used to turn the \f(CW\*(C`line\*(C'\fR off (it is always on by default except in Scatter charts). This is useful if you wish to plot a series with markers but without a line. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& line => { none => 1 }, \& ); .Ve .PP The \f(CW\*(C`color\*(C'\fR property sets the color of the \f(CW\*(C`line\*(C'\fR. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& line => { color => \*(Aqred\*(Aq }, \& ); .Ve .PP The available colours are shown in the main Excel::Writer::XLSX documentation. It is also possible to set the colour of a line with a \s-1HTML\s0 style \s-1RGB\s0 colour: .PP .Vb 3 \& $chart\->add_series( \& line => { color => \*(Aq#FF0000\*(Aq }, \& ); .Ve .PP The \f(CW\*(C`width\*(C'\fR property sets the width of the \f(CW\*(C`line\*(C'\fR. It should be specified in increments of 0.25 of a point as in Excel. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& line => { width => 3.25 }, \& ); .Ve .PP The \f(CW\*(C`dash_type\*(C'\fR property sets the dash style of the line. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& line => { dash_type => \*(Aqdash_dot\*(Aq }, \& ); .Ve .PP The following \f(CW\*(C`dash_type\*(C'\fR values are available. They are shown in the order that they appear in the Excel dialog. .PP .Vb 8 \& solid \& round_dot \& square_dot \& dash \& dash_dot \& long_dash \& long_dash_dot \& long_dash_dot_dot .Ve .PP The default line style is \f(CW\*(C`solid\*(C'\fR. .PP The \f(CW\*(C`transparency\*(C'\fR property sets the transparency of the \f(CW\*(C`line\*(C'\fR color in the integer range 1 \- 100. The color must be set for transparency to work, it doesn't work with an automatic/default color: .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& line => { color => \*(Aqyellow\*(Aq, transparency => 50 }, \& ); .Ve .PP More than one \f(CW\*(C`line\*(C'\fR property can be specified at a time: .PP .Vb 8 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& line => { \& color => \*(Aqred\*(Aq, \& width => 1.25, \& dash_type => \*(Aqsquare_dot\*(Aq, \& }, \& ); .Ve .SS "Border" .IX Subsection "Border" The \f(CW\*(C`border\*(C'\fR property is a synonym for \f(CW\*(C`line\*(C'\fR. .PP It can be used as a descriptive substitute for \f(CW\*(C`line\*(C'\fR in chart types such as Bar and Column that have a border and fill style rather than a line style. In general chart objects with a \f(CW\*(C`border\*(C'\fR property will also have a fill property. .SS "Solid Fill" .IX Subsection "Solid Fill" The fill format is used to specify filled areas of chart objects such as the interior of a column or the background of the chart itself. .PP The following properties can be set for \f(CW\*(C`fill\*(C'\fR formats in a chart. .PP .Vb 3 \& none \& color \& transparency .Ve .PP The \f(CW\*(C`none\*(C'\fR property is used to turn the \f(CW\*(C`fill\*(C'\fR property off (it is generally on by default). .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& fill => { none => 1 }, \& ); .Ve .PP The \f(CW\*(C`color\*(C'\fR property sets the colour of the \f(CW\*(C`fill\*(C'\fR area. .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& fill => { color => \*(Aqred\*(Aq }, \& ); .Ve .PP The available colours are shown in the main Excel::Writer::XLSX documentation. It is also possible to set the colour of a fill with a \s-1HTML\s0 style \s-1RGB\s0 colour: .PP .Vb 3 \& $chart\->add_series( \& fill => { color => \*(Aq#FF0000\*(Aq }, \& ); .Ve .PP The \f(CW\*(C`transparency\*(C'\fR property sets the transparency of the solid fill color in the integer range 1 \- 100. The color must be set for transparency to work, it doesn't work with an automatic/default color: .PP .Vb 1 \& $chart\->set_chartarea( fill => { color => \*(Aqyellow\*(Aq, transparency => 75 } ); .Ve .PP The \f(CW\*(C`fill\*(C'\fR format is generally used in conjunction with a \f(CW\*(C`border\*(C'\fR format which has the same properties as a \f(CW\*(C`line\*(C'\fR format. .PP .Vb 5 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$5\*(Aq, \& border => { color => \*(Aqred\*(Aq }, \& fill => { color => \*(Aqyellow\*(Aq }, \& ); .Ve .SS "Pattern Fill" .IX Subsection "Pattern Fill" The pattern fill format is used to specify pattern filled areas of chart objects such as the interior of a column or the background of the chart itself. .PP The following properties can be set for \f(CW\*(C`pattern\*(C'\fR fill formats in a chart: .PP .Vb 3 \& pattern: the pattern to be applied (required) \& fg_color: the foreground color of the pattern (required) \& bg_color: the background color (optional, defaults to white) .Ve .PP For example: .PP .Vb 7 \& $chart\->set_plotarea( \& pattern => { \& pattern => \*(Aqpercent_5\*(Aq, \& fg_color => \*(Aqred\*(Aq, \& bg_color => \*(Aqyellow\*(Aq, \& } \& ); .Ve .PP The following patterns can be applied: .PP .Vb 10 \& percent_5 \& percent_10 \& percent_20 \& percent_25 \& percent_30 \& percent_40 \& percent_50 \& percent_60 \& percent_70 \& percent_75 \& percent_80 \& percent_90 \& light_downward_diagonal \& light_upward_diagonal \& dark_downward_diagonal \& dark_upward_diagonal \& wide_downward_diagonal \& wide_upward_diagonal \& light_vertical \& light_horizontal \& narrow_vertical \& narrow_horizontal \& dark_vertical \& dark_horizontal \& dashed_downward_diagonal \& dashed_upward_diagonal \& dashed_horizontal \& dashed_vertical \& small_confetti \& large_confetti \& zigzag \& wave \& diagonal_brick \& horizontal_brick \& weave \& plaid \& divot \& dotted_grid \& dotted_diamond \& shingle \& trellis \& sphere \& small_grid \& large_grid \& small_check \& large_check \& outlined_diamond \& solid_diamond .Ve .PP The foreground color, \f(CW\*(C`fg_color\*(C'\fR, is a required parameter and can be a Html style \f(CW\*(C`#RRGGBB\*(C'\fR string or a limited number of named colors. The available colours are shown in the main Excel::Writer::XLSX documentation. .PP The background color, \f(CW\*(C`bg_color\*(C'\fR, is optional and defaults to black. .PP If a pattern fill is used on a chart object it overrides the solid fill properties of the object. .SS "Gradient Fill" .IX Subsection "Gradient Fill" The gradient fill format is used to specify gradient filled areas of chart objects such as the interior of a column or the background of the chart itself. .PP The following properties can be set for \f(CW\*(C`gradient\*(C'\fR fill formats in a chart: .PP .Vb 4 \& colors: a list of colors \& positions: an optional list of positions for the colors \& type: the optional type of gradient fill \& angle: the optional angle of the linear fill .Ve .PP The \f(CW\*(C`colors\*(C'\fR property sets a list of colors that define the \f(CW\*(C`gradient\*(C'\fR: .PP .Vb 3 \& $chart\->set_plotarea( \& gradient => { colors => [ \*(Aq#DDEBCF\*(Aq, \*(Aq#9CB86E\*(Aq, \*(Aq#156B13\*(Aq ] } \& ); .Ve .PP Excel allows between 2 and 10 colors in a gradient but it is unlikely that you will require more than 2 or 3. .PP As with solid or pattern fill it is also possible to set the colors of a gradient with a Html style \f(CW\*(C`#RRGGBB\*(C'\fR string or a limited number of named colors. The available colours are shown in the main Excel::Writer::XLSX documentation: .PP .Vb 4 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$A$1:$A$5\*(Aq, \& gradient => { colors => [ \*(Aqred\*(Aq, \*(Aqgreen\*(Aq ] } \& ); .Ve .PP The \f(CW\*(C`positions\*(C'\fR defines an optional list of positions, between 0 and 100, of where the colors in the gradient are located. Default values are provided for \&\f(CW\*(C`colors\*(C'\fR lists of between 2 and 4 but they can be specified if required: .PP .Vb 7 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$A$1:$A$5\*(Aq, \& gradient => { \& colors => [ \*(Aq#DDEBCF\*(Aq, \*(Aq#156B13\*(Aq ], \& positions => [ 10, 90 ], \& } \& ); .Ve .PP The \f(CW\*(C`type\*(C'\fR property can have one of the following values: .PP .Vb 4 \& linear (the default) \& radial \& rectangular \& path .Ve .PP For example: .PP .Vb 7 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$A$1:$A$5\*(Aq, \& gradient => { \& colors => [ \*(Aq#DDEBCF\*(Aq, \*(Aq#9CB86E\*(Aq, \*(Aq#156B13\*(Aq ], \& type => \*(Aqradial\*(Aq \& } \& ); .Ve .PP If \f(CW\*(C`type\*(C'\fR isn't specified it defaults to \f(CW\*(C`linear\*(C'\fR. .PP For a \f(CW\*(C`linear\*(C'\fR fill the angle of the gradient can also be specified: .PP .Vb 5 \& $chart\->add_series( \& values => \*(Aq=Sheet1!$A$1:$A$5\*(Aq, \& gradient => { colors => [ \*(Aq#DDEBCF\*(Aq, \*(Aq#9CB86E\*(Aq, \*(Aq#156B13\*(Aq ], \& angle => 30 } \& ); .Ve .PP The default angle is 90 degrees. .PP If gradient fill is used on a chart object it overrides the solid fill and pattern fill properties of the object. .SH "CHART FONTS" .IX Header "CHART FONTS" The following font properties can be set for any chart object that they apply to (and that are supported by Excel::Writer::XLSX) such as chart titles, axis labels, axis numbering and data labels. They correspond to the equivalent Worksheet cell Format object properties. See \*(L"\s-1FORMAT_METHODS\*(R"\s0 in Excel::Writer::XLSX for more information. .PP .Vb 7 \& name \& size \& bold \& italic \& underline \& rotation \& color .Ve .PP The following explains the available font properties: .IP "\(bu" 4 \&\f(CW\*(C`name\*(C'\fR .Sp Set the font name: .Sp .Vb 1 \& $chart\->set_x_axis( num_font => { name => \*(AqArial\*(Aq } ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`size\*(C'\fR .Sp Set the font size: .Sp .Vb 1 \& $chart\->set_x_axis( num_font => { name => \*(AqArial\*(Aq, size => 10 } ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`bold\*(C'\fR .Sp Set the font bold property, should be 0 or 1: .Sp .Vb 1 \& $chart\->set_x_axis( num_font => { bold => 1 } ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`italic\*(C'\fR .Sp Set the font italic property, should be 0 or 1: .Sp .Vb 1 \& $chart\->set_x_axis( num_font => { italic => 1 } ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`underline\*(C'\fR .Sp Set the font underline property, should be 0 or 1: .Sp .Vb 1 \& $chart\->set_x_axis( num_font => { underline => 1 } ); .Ve .IP "\(bu" 4 \&\f(CW\*(C`rotation\*(C'\fR .Sp Set the font rotation in the integer range \-90 to 90, and 270\-271: .Sp .Vb 1 \& $chart\->set_x_axis( num_font => { rotation => 45 } ); .Ve .Sp This is useful for displaying large axis data such as dates in a more compact format. .Sp There are 2 special case angles outside the range \-90 to 90: .RS 4 .IP "\(bu" 4 270: Stacked text, where the text runs from top to bottom. .IP "\(bu" 4 271: A special variant of stacked text for East Asian fonts. .RE .RS 4 .RE .IP "\(bu" 4 \&\f(CW\*(C`color\*(C'\fR .Sp Set the font color property. Can be a color index, a color name or \s-1HTML\s0 style \s-1RGB\s0 colour: .Sp .Vb 2 \& $chart\->set_x_axis( num_font => { color => \*(Aqred\*(Aq } ); \& $chart\->set_y_axis( num_font => { color => \*(Aq#92D050\*(Aq } ); .Ve .PP Here is an example of Font formatting in a Chart program: .PP .Vb 8 \& # Format the chart title. \& $chart\->set_title( \& name => \*(AqSales Results Chart\*(Aq, \& name_font => { \& name => \*(AqCalibri\*(Aq, \& color => \*(Aqyellow\*(Aq, \& }, \& ); \& \& # Format the X\-axis. \& $chart\->set_x_axis( \& name => \*(AqMonth\*(Aq, \& name_font => { \& name => \*(AqArial\*(Aq, \& color => \*(Aq#92D050\*(Aq \& }, \& num_font => { \& name => \*(AqCourier New\*(Aq, \& color => \*(Aq#00B0F0\*(Aq, \& }, \& ); \& \& # Format the Y\-axis. \& $chart\->set_y_axis( \& name => \*(AqSales (1000 units)\*(Aq, \& name_font => { \& name => \*(AqCentury\*(Aq, \& underline => 1, \& color => \*(Aqred\*(Aq \& }, \& num_font => { \& bold => 1, \& italic => 1, \& color => \*(Aq#7030A0\*(Aq, \& }, \& ); .Ve .SH "CHART LAYOUT" .IX Header "CHART LAYOUT" The position of the chart in the worksheet is controlled by the \f(CW\*(C`set_size()\*(C'\fR method shown above. .PP It is also possible to change the layout of the following chart sub-objects: .PP .Vb 5 \& plotarea \& legend \& title \& x_axis caption \& y_axis caption .Ve .PP Here are some examples: .PP .Vb 8 \& $chart\->set_plotarea( \& layout => { \& x => 0.35, \& y => 0.26, \& width => 0.62, \& height => 0.50, \& } \& ); \& \& $chart\->set_legend( \& layout => { \& x => 0.80, \& y => 0.37, \& width => 0.12, \& height => 0.25, \& } \& ); \& \& $chart\->set_title( \& name => \*(AqTitle\*(Aq, \& layout => { \& x => 0.42, \& y => 0.14, \& } \& ); \& \& $chart\->set_x_axis( \& name => \*(AqX axis\*(Aq, \& name_layout => { \& x => 0.34, \& y => 0.85, \& } \& ); .Ve .PP Note that it is only possible to change the width and height for the \f(CW\*(C`plotarea\*(C'\fR and \f(CW\*(C`legend\*(C'\fR objects. For the other text based objects the width and height are changed by the font dimensions. .PP The layout units must be a float in the range \f(CW\*(C`0 < x <= 1\*(C'\fR and are expressed as a percentage of the chart dimensions as shown below: .PP From this the layout units are calculated as follows: .PP .Vb 5 \& layout: \& width = w / W \& height = h / H \& x = a / W \& y = b / H .Ve .PP These units are slightly cumbersome but are required by Excel so that the chart object positions remain relative to each other if the chart is resized by the user. .PP Note that for \f(CW\*(C`plotarea\*(C'\fR the origin is the top left corner in the plotarea itself and does not take into account the axes. .SH "WORKSHEET METHODS" .IX Header "WORKSHEET METHODS" In Excel a chartsheet (i.e, a chart that isn't embedded) shares properties with data worksheets such as tab selection, headers, footers, margins, and print properties. .PP In Excel::Writer::XLSX you can set chartsheet properties using the same methods that are used for Worksheet objects. .PP The following Worksheet methods are also available through a non-embedded Chart object: .PP .Vb 8 \& get_name() \& activate() \& select() \& hide() \& set_first_sheet() \& protect() \& set_zoom() \& set_tab_color() \& \& set_landscape() \& set_portrait() \& set_paper() \& set_margins() \& set_header() \& set_footer() .Ve .PP See Excel::Writer::XLSX for a detailed explanation of these methods. .SH "EXAMPLE" .IX Header "EXAMPLE" Here is a complete example that demonstrates some of the available features when creating a chart. .PP .Vb 1 \& #!/usr/bin/perl \& \& use strict; \& use warnings; \& use Excel::Writer::XLSX; \& \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqchart.xlsx\*(Aq ); \& my $worksheet = $workbook\->add_worksheet(); \& my $bold = $workbook\->add_format( bold => 1 ); \& \& # Add the worksheet data that the charts will refer to. \& my $headings = [ \*(AqNumber\*(Aq, \*(AqBatch 1\*(Aq, \*(AqBatch 2\*(Aq ]; \& my $data = [ \& [ 2, 3, 4, 5, 6, 7 ], \& [ 10, 40, 50, 20, 10, 50 ], \& [ 30, 60, 70, 50, 40, 30 ], \& \& ]; \& \& $worksheet\->write( \*(AqA1\*(Aq, $headings, $bold ); \& $worksheet\->write( \*(AqA2\*(Aq, $data ); \& \& # Create a new chart object. In this case an embedded chart. \& my $chart = $workbook\->add_chart( type => \*(Aqcolumn\*(Aq, embedded => 1 ); \& \& # Configure the first series. \& $chart\->add_series( \& name => \*(Aq=Sheet1!$B$1\*(Aq, \& categories => \*(Aq=Sheet1!$A$2:$A$7\*(Aq, \& values => \*(Aq=Sheet1!$B$2:$B$7\*(Aq, \& ); \& \& # Configure second series. Note alternative use of array ref to define \& # ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ]. \& $chart\->add_series( \& name => \*(Aq=Sheet1!$C$1\*(Aq, \& categories => [ \*(AqSheet1\*(Aq, 1, 6, 0, 0 ], \& values => [ \*(AqSheet1\*(Aq, 1, 6, 2, 2 ], \& ); \& \& # Add a chart title and some axis labels. \& $chart\->set_title ( name => \*(AqResults of sample analysis\*(Aq ); \& $chart\->set_x_axis( name => \*(AqTest number\*(Aq ); \& $chart\->set_y_axis( name => \*(AqSample length (mm)\*(Aq ); \& \& # Set an Excel chart style. Blue colors with white outline and shadow. \& $chart\->set_style( 11 ); \& \& # Insert the chart into the worksheet (with an offset). \& $worksheet\->insert_chart( \*(AqD2\*(Aq, $chart, { x_offset => 25, y_offset => 10 } ); \& \& $workbook\->close(); \& \& _\|_END_\|_ .Ve .SH "Value and Category Axes" .IX Header "Value and Category Axes" Excel differentiates between a chart axis that is used for series \fBcategories\fR and an axis that is used for series \fBvalues\fR. .PP In the example above the X axis is the category axis and each of the values is evenly spaced. The Y axis (in this case) is the value axis and points are displayed according to their value. .PP Since Excel treats the axes differently it also handles their formatting differently and exposes different properties for each. .PP As such some of \f(CW\*(C`Excel::Writer::XLSX\*(C'\fR axis properties can be set for a value axis, some can be set for a category axis and some properties can be set for both. .PP For example the \f(CW\*(C`min\*(C'\fR and \f(CW\*(C`max\*(C'\fR properties can only be set for value axes and \f(CW\*(C`reverse\*(C'\fR can be set for both. The type of axis that a property applies to is shown in the \f(CW\*(C`set_x_axis()\*(C'\fR section of the documentation above. .PP Some charts such as \f(CW\*(C`Scatter\*(C'\fR and \f(CW\*(C`Stock\*(C'\fR have two value axes. .PP Date Axes are a special type of category axis which are explained below. .SH "Date Category Axes" .IX Header "Date Category Axes" Date Category Axes are category axes that display time or date information. In Excel::Writer::XLSX Date Category Axes are set using the \f(CW\*(C`date_axis\*(C'\fR option: .PP .Vb 1 \& $chart\->set_x_axis( date_axis => 1 ); .Ve .PP In general you should also specify a number format for a date axis although Excel will usually default to the same format as the data being plotted: .PP .Vb 4 \& $chart\->set_x_axis( \& date_axis => 1, \& num_format => \*(Aqdd/mm/yyyy\*(Aq, \& ); .Ve .PP Excel doesn't normally allow minimum and maximum values to be set for category axes. However, date axes are an exception. The \f(CW\*(C`min\*(C'\fR and \f(CW\*(C`max\*(C'\fR values should be set as Excel times or dates: .PP .Vb 6 \& $chart\->set_x_axis( \& date_axis => 1, \& min => $worksheet\->convert_date_time(\*(Aq2013\-01\-02T\*(Aq), \& max => $worksheet\->convert_date_time(\*(Aq2013\-01\-09T\*(Aq), \& num_format => \*(Aqdd/mm/yyyy\*(Aq, \& ); .Ve .PP For date axes it is also possible to set the type of the major and minor units: .PP .Vb 8 \& $chart\->set_x_axis( \& date_axis => 1, \& minor_unit => 4, \& minor_unit_type => \*(Aqmonths\*(Aq, \& major_unit => 1, \& major_unit_type => \*(Aqyears\*(Aq, \& num_format => \*(Aqdd/mm/yyyy\*(Aq, \& ); .Ve .SH "Secondary Axes" .IX Header "Secondary Axes" It is possible to add a secondary axis of the same type to a chart by setting the \f(CW\*(C`y2_axis\*(C'\fR or \f(CW\*(C`x2_axis\*(C'\fR property of the series: .PP .Vb 1 \& #!/usr/bin/perl \& \& use strict; \& use warnings; \& use Excel::Writer::XLSX; \& \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqchart_secondary_axis.xlsx\*(Aq ); \& my $worksheet = $workbook\->add_worksheet(); \& \& # Add the worksheet data that the charts will refer to. \& my $data = [ \& [ 2, 3, 4, 5, 6, 7 ], \& [ 10, 40, 50, 20, 10, 50 ], \& \& ]; \& \& $worksheet\->write( \*(AqA1\*(Aq, $data ); \& \& # Create a new chart object. In this case an embedded chart. \& my $chart = $workbook\->add_chart( type => \*(Aqline\*(Aq, embedded => 1 ); \& \& # Configure a series with a secondary axis \& $chart\->add_series( \& values => \*(Aq=Sheet1!$A$1:$A$6\*(Aq, \& y2_axis => 1, \& ); \& \& $chart\->add_series( \& values => \*(Aq=Sheet1!$B$1:$B$6\*(Aq, \& ); \& \& \& # Insert the chart into the worksheet. \& $worksheet\->insert_chart( \*(AqD2\*(Aq, $chart ); \& \& $workbook\->close(); \& \& _\|_END_\|_ .Ve .PP It is also possible to have a secondary, combined, chart either with a shared or secondary axis, see below. .SH "Combined Charts" .IX Header "Combined Charts" It is also possible to combine two different chart types, for example a column and line chart to create a Pareto chart using the Chart \f(CW\*(C`combine()\*(C'\fR method: .PP Here is a simpler example: .PP .Vb 3 \& use strict; \& use warnings; \& use Excel::Writer::XLSX; \& \& my $workbook = Excel::Writer::XLSX\->new( \*(Aqchart_combined.xlsx\*(Aq ); \& my $worksheet = $workbook\->add_worksheet(); \& my $bold = $workbook\->add_format( bold => 1 ); \& \& # Add the worksheet data that the charts will refer to. \& my $headings = [ \*(AqNumber\*(Aq, \*(AqBatch 1\*(Aq, \*(AqBatch 2\*(Aq ]; \& my $data = [ \& [ 2, 3, 4, 5, 6, 7 ], \& [ 10, 40, 50, 20, 10, 50 ], \& [ 30, 60, 70, 50, 40, 30 ], \& \& ]; \& \& $worksheet\->write( \*(AqA1\*(Aq, $headings, $bold ); \& $worksheet\->write( \*(AqA2\*(Aq, $data ); \& \& # \& # In the first example we will create a combined column and line chart. \& # They will share the same X and Y axes. \& # \& \& # Create a new column chart. This will use this as the primary chart. \& my $column_chart = $workbook\->add_chart( type => \*(Aqcolumn\*(Aq, embedded => 1 ); \& \& # Configure the data series for the primary chart. \& $column_chart\->add_series( \& name => \*(Aq=Sheet1!$B$1\*(Aq, \& categories => \*(Aq=Sheet1!$A$2:$A$7\*(Aq, \& values => \*(Aq=Sheet1!$B$2:$B$7\*(Aq, \& ); \& \& # Create a new column chart. This will use this as the secondary chart. \& my $line_chart = $workbook\->add_chart( type => \*(Aqline\*(Aq, embedded => 1 ); \& \& # Configure the data series for the secondary chart. \& $line_chart\->add_series( \& name => \*(Aq=Sheet1!$C$1\*(Aq, \& categories => \*(Aq=Sheet1!$A$2:$A$7\*(Aq, \& values => \*(Aq=Sheet1!$C$2:$C$7\*(Aq, \& ); \& \& # Combine the charts. \& $column_chart\->combine( $line_chart ); \& \& # Add a chart title and some axis labels. Note, this is done via the \& # primary chart. \& $column_chart\->set_title( name => \*(AqCombined chart \- same Y axis\*(Aq ); \& $column_chart\->set_x_axis( name => \*(AqTest number\*(Aq ); \& $column_chart\->set_y_axis( name => \*(AqSample length (mm)\*(Aq ); \& \& \& # Insert the chart into the worksheet \& $worksheet\->insert_chart( \*(AqE2\*(Aq, $column_chart ); \& \& $workbook\->close(); .Ve .PP The secondary chart can also be placed on a secondary axis using the methods shown in the previous section. .PP In this case it is just necessary to add a \f(CW\*(C`y2_axis\*(C'\fR parameter to the series and, if required, add a title using \f(CW\*(C`set_y2_axis()\*(C'\fR \fBof the secondary chart\fR. The following are the additions to the previous example to place the secondary chart on the secondary axis: .PP .Vb 1 \& ... \& \& $line_chart\->add_series( \& name => \*(Aq=Sheet1!$C$1\*(Aq, \& categories => \*(Aq=Sheet1!$A$2:$A$7\*(Aq, \& values => \*(Aq=Sheet1!$C$2:$C$7\*(Aq, \& y2_axis => 1, \& ); \& \& ... \& \& # Note: the y2 properites are on the secondary chart. \& $line_chart2\->set_y2_axis( name => \*(AqTarget length (mm)\*(Aq ); .Ve .PP The examples above use the concept of a \fIprimary\fR and \fIsecondary\fR chart. The primary chart is the chart that defines the primary X and Y axis. It is also used for setting all chart properties apart from the secondary data series. For example the chart title and axes properties should be set via the primary chart (except for the the secondary \f(CW\*(C`y2\*(C'\fR axis properties which should be applied to the secondary chart). .PP See also \f(CW\*(C`chart_combined.pl\*(C'\fR and \f(CW\*(C`chart_pareto.pl\*(C'\fR examples in the distro for more detailed examples. .PP There are some limitations on combined charts: .IP "\(bu" 4 Pie charts cannot currently be combined. .IP "\(bu" 4 Scatter charts cannot currently be used as a primary chart but they can be used as a secondary chart. .IP "\(bu" 4 Bar charts can only combined secondary charts on a secondary axis. This is an Excel limitation. .SH "AUTHOR" .IX Header "AUTHOR" John McNamara jmcnamara@cpan.org .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright MM-MMXXIII, John McNamara. .PP All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.