addChart

addChart

BASIC / ADVANCED / PREMIUM

Inserts a chart into a Word document.

Description
public addChart ( array $options )

This method allows the insertion of a chart into your Word document.

You may insert many different type of 2D and 3D charts:

  • 2D
    • Bar (clustered, stacked and 100% stacked).
    • Column (clustered, stacked and 100% stacked).
    • Pie (simple, exploded, pie of pie and bar of pie).
    • Doughnut.
    • Line.
    • Area.
    • Surface.
    • Radar.
    • XY(scatter).
    • Bubble.
  • 3D
    • Bar: box (default), cylinder, cone, and pyramid (clustered, stacked and 100% stacked).
    • Column: box (default), cylinder, cone, and pyramid (clustered, stacked and 100% stacked).
    • Pie (simple and exploded).
    • Surface.
    • Line.

This method also allows adding combo charts, trendlines, grids, labels and many other chart features.

Parameters

options

This is an array with the following possible keys and values.

Key Type Description
data array This array should contain the legends and data and to be represented in the following format:
'data' => array( 'legend' => array('Series 1', 'Series 2', 'Series 3'), 'data' => array( array( 'name' => 'data 1', 'values' => array(10, 20, 30), ), array( 'name' => 'data 2', 'values' => array(20, 4, 5), ), array( 'name' => 'data 3', 'values' => array(10, 0, 2), ), ) )
You should omit the legend array in charts for which each data array only contains one value like, for example, in the case of pie charts.
type String The possible values are:
  • barChart
  • bar3DChart
  • bar3DChartCylinder
  • bar3DChartCone
  • bar3DChartPyramid
  • colChart
  • col3DChart
  • col3DChartCylinder
  • col3DChartCone
  • bar3DChartPyramid
  • pieChart
  • pie3DChart
  • ofPieChart (pie of pie and bar of pie charts)
  • lineChart
  • line3DChart
  • areaChart
  • area3DChart
  • radarChart
  • scatterChart
  • bubbleChart
  • doughnutChart
  • surfaceChart
title string The chart title (if any).
border string Border width in points.
chartAlign string Chart alignment: left (default), right or center.
color int Word color scheme for charts:
  • 1: greyscale.
  • 2: default Word color scheme for charts.
  • 3: blue scheme.
  • For the remaining color schemes (up to 48) check the Word interface.
comboChart string Chart to add a as combo chart. Use with the returnChart option. Global styles and properties are shared with the base chart. For bar, col, line, area, and radar charts.
customStyle string Set external color and styles files imported using the importChartStyle method.
externalXLSX array Possible keys and values are:
  • src => (string) path to the external file.
  • occurrences => (array) (optional) by default the option adds all charts of the source file. If occurrences is not empty, it adds the referenced positions. Value from 1.
float string Floating chart: left, right or center. It only applies if textWrap is not inline (default value).
font string The font to be used. Arial, Calibri...
returnChart bool False as default, if true return the XML of the chart. To be used with the comboChart option.
sizeX int The chart width in centimeters (default value aprox 8.5 cm).
sizeY int The chart height in centimeters (default value aprox 6.0 cm).
textWrap int The way text shoud wrap the chart. Possible values are (check in the Word interface for the graphical explanation of the different terms):
  • 0 (inline)
  • 1 (square)
  • 2 (front)
  • 3 (back)
  • 4 (up and bottom)
trendline array Adds trendlines. Compatible with line, bar, col and area 2D charts. Possible keys and values are:
  • color => (string) 0000ff.
  • display_equation => (bool) display equation on chart.
  • display_rSquared => (bool) display R-squared value on chart.
  • intercept => (float) set intercept.
  • line_style => (string) solid, dot, dash, lgDash, dashDot, lgDashDot, lgDashDotDot, sysDash, sysDot, sysDashDot, sysDashDotDot.
  • type => (string) exp, linear, log, poly, power, movingAvg.
  • type_order => (int) for poly and movingAvg types.

Chart display properties

Key Type Description
formatCode string Number format.
formatDataLabels array Possible keys and values are:
  • rotation => (int).
  • position => (string) center, insideEnd, insideBase, outsideEnd.
haxLabel string Label for the horizontal axis.
haxLabelDisplay bool How to display the label of the horizontal axis. Possible values are: vertical, horizontal, rotated.
hgrid int Horizontal grid. Possible values are:
  • 0 (no grid)
  • 1 (only major grid lines - default)
  • 2 (only minor grid lines)
  • 3 (both major and minor grid lines)
horizontalOffset int Given in emus (1cm = 360000 emus).
majorUnit float Major unit value for bar, col, line, area, radar and scatter charts.
minorUnit float Minor unit value for bar, col, line, area, radar and scatter charts.
scalingMax float Scaling max value for bar, col, line, area, radar and scatter charts.
scalingMin float Scaling max value for bar, col, line, area, radar and scatter charts.
stylesTitle array Possible keys and values are:
  • bold => (boolean).
  • color => (string) ffffff, ff0000....
  • font => (string) Arial, Times New Roman....
  • fontSize => (int) 1420, 2000... Size as drawing content (10 to 400000). 1420 as default..
  • italic => (boolean).
vaxLabel string Label for the vertical axis.
vaxLabelDisplay bool How to display the label of the horizontal axis. Possible values are: vertical, horizontal, rotated.
verticalOffset int Given in emus (1cm = 360000 emus).
vgrid int Vertical grid. Possible values are:
  • 0 (no grid)
  • 1 (only major grid lines - default)
  • 2 (only minor grid lines)
  • 3 (both major and minor grid lines)

The available parameters to display legends and data include:

Key Type Description
legendOverlay bool If true the legend may overlay the chart. This option may hinder the legibility of tha data so it is only recommended if it is crucial to "save space".
legendPos string The possible values are:
  • b (bottom)
  • l (left)
  • r (right)
  • t (top)
  • none
showCategory bool If true shows the categories inside the chart.
showLegendKey bool If true shows the legend values.
showPercent bool If true shows the percentage values.
showSeries bool If true shows the series values.
showTable bool If true shows the chart data in an associated table.
showValue bool If true shows the chart data values.

Further configuration options for specific chart types are:

Key Type Description
Bar and column charts
groupBar string Different ways to group the data. Possible values are: clustered, stacked, percentStacked and standard.
tickLblPos string Tick label position.
Pie and doughnut charts
explosion int Distance among different sectors.
holeSize int Size of the inner hole (only doughnut charts).
ofPieCharts: pie of pie and bar of pie charts
custSplit array Custom split. Array (zero based) of values that goes in the second chart. For example: array(3,4,7) will pick the fourth, fifth and eigth value.
gapWidth int Distance between the two charts.
secondPieSize int Percentage size of the auxiliary chart.
splitType string How to split the two charts. Possible values are:
  • auto (default split type)
  • cust (custom Split)
  • percent (split by percentage)
  • pos (split by position)
  • val (split by value)
splitPos int Determines the threshold value to split the charts.
subtype string Defines if the auxiliary chart is a pie or bar chart. Possible values are pie or bar.
Line and scatter (XY) charts
smooth bool If true it smooths the line (only scatter charts).
symbol string The possible symbol values are:
  • Line charts: none, dot, plus, square, star, triangle, x, diamond, circle and dash.
  • Scatter charts: dot and line.
symbolSize int The size of the symbol used.
Radar charts
style string Defines the radar chart style. Possible values are:
  • radar (lines without dots)
  • marker (lines with dots)
  • filled (filled enclosed area)
Surface charts
wireframe bool If true the surface is shown as a wireframe.

Additional available options for 3D charts:

Key Type Description
perspective int Perspective angle. Angles beyond 25 degrees provoke a big distortion in the 3D chart representation.
rotX int Rotation angle respect the vertical axis. Standard values are between 10 and 20 degrees.
rotY int Rotation angle respect the horizontal axis. Standard values are between 10 and 20 degrees.

Theme options (Only available in Premium licenses):

key Type Description
chartArea array backgroundColor
horizontalAxis array textBold, textDirection (horizontal, rotate90, rotate270), textItalic, textSize, textUnderline (DrawingML values such as none, sng, dash)
legendArea array backgroundColor
plotArea array backgroundColor
serRgbColors array series colors
valueRgbColors array values colors
verticalAxis array textBold, textDirection (horizontal, rotate90, rotate270), textItalic, textSize, textUnderline (DrawingML values such as none, sng, dash)
Return values

Chart object. To be used as combo chart.

Code samples

Example #1

The resulting Word document looks like:

Example #2

The resulting Word document looks like:

Example #3

The resulting Word document looks like:

Example #4

The resulting Word document looks like: