The seamless integration of chart generation within Docxpresso is one of its more distinctive features.
One may create with a few lines of code truly sophisticated and fully customizable 2D and 3D charts.
Currently the following chart types are available:
- 2D:
- column,
- bar,
- pie,
- donut,
- area,
- line,
- scatter,
- bubble,
- radar,
- filled-radar and
- column-line.
- 3D:
- 3Dcolumn,
- 3Dbar,
- 3Dpie,
- 3Ddonut,
- 3Darea,
- 3Dline and
- 3Dscatter.
The support for charts in .docx format is still incomplete so you should double check the results or use .doc output format if MS Word is the target of your choice.
Like you can imagine the public API for the generation of charts is “pretty big” so, in order to facilitate your work, Docxpresso offers a number of auxiliary methods that allows to better organize your code. Namely:
- chart3DTransform: specifies the 3D rendering properties of a chart: rotation angles and perspective.
- chartAxis: allows to customize the different properties of the chart x, y and z axis: labels, tick lines, etcetera
- chartComponent: allows for the customization of the chart wall and floor: background-color and border lines.
- chartData: inserts the actual data together with its styling options: color, lines, etcetera.
- chartGrid: sets the chart grid properties for the different grids: major and minor.
- chartLegend: specifies the chart legend properties: position, font properties, etcetera.
It is, of course, not mandatory to specify all of this properties for every chart: some of them are completely optional and other will default to pre-established values that may serve your purposes most of the times.
Let us now pass to describe in detail the APIs of these different methods and illustrate their respective functionality with a few examples.
Beware that you may also generate your charts using Docxpresso extended HTML5 code: Advanced document components via extended HTML5.
Chart method
The chart method is the responsible to generate the basic chart that may be later decorated with the help of the other chart methods described above.
Its public API is given by:
Signature
public chart ($chartType [, $options])
Parameters
- $chartType (type: string). The available types are:
- 2D: column, bar, pie, donut, area, line, scatter, bubble, radar, filled-radar and column-line.
- 3D: 3Dcolumn, 3Dbar, 3Dpie, 3Ddonut, 3Darea, 3Dline and 3Dscatter.
- $options (type: array).
This array has the following available keys and values:- data (type: array),
it can be an array with different formats:- pie and donut charts:
array(
‘category_1’ => 3,
‘category_2’ => 5,
‘category_3’ => 4.3,
) - bar, column, area , line, scatter, (filled-)radar and column-line charts:
array(
‘series’ => array(‘series_1’, ‘series_2’),
‘category_1’ => array(20,40),
‘category_2’ => array(30,10),
‘category_3’ => array(12.5, 54),
) - bubble charts:
array(
array(2, 5 7),
array(4.3, 12, 3.5),
array(6, 3, 5),
)
- pie and donut charts:
- chart-properties (type: array).
An array with the following keys and values:- data-label-number (type: string, default: none). The possible values are: none, value or percentage.
- label-position (type: string). The possible values are: avoid-overlap, center, top, top-right, right, bottom-right, bottom, bottom-left, left, top-left, inside, outside or near-origin.
- label-position-negative (type: string). It only applies if the data value is negative. If not given the label-position value will be used. Possible values are: top-left, inside, outside or near-origin.
- hole-size (type: integer), specifies the diameter of the inner hole of a ring chart as percentage of the outer diameter of the outermost ring.
- pie-offset (type: integer), specifies the distance of a segment from the center of the circle in case of circle charts. The offset is given as an integer which is interpreted as a percentage of the radius of the circle. In case of ring charts specifies an additional distance of a segment from the center of the circle. The distance is given as percentage of the thickness of the ring.
- angle-offset (type: integer), specifies in degrees a counter clockwise rotation of a polar coordinate in a circle, ring or polar chart.
- stacked (type: boolean, default: false).It specifies the accumulation of the series values per category. Each value is in addition to the other values in the same category.
- gap-width (type: integer), specifies a gap between neighboring groups of bars in a bar/column chart. It is specified as an integer percentage relative to the width of a single bar (negative values split the bars apart).
- overlap (type: integer), specifies how much bars within the same category in a bar/column chart overlap. The attribute value is an integer that is interpreted as a percentage relative to the width of a bar. Negative values specify gaps between bars.
- percentage (type: boolean). If true specifies a percentage accumulation of values per category.
- chart-interpolation (type: string). The possible values are none (if points are to be connected by a straight line), b-spline or cubic-spline.
- spline-resolution (type: integer). It only applies if the chart-interpolation option is not equal to none.
- deep (type: boolean, default: false). If true the series will be shown in 3D one behind the other and not side by side. It only applies to 3D charts.
- solid-type (type: string, default: cuboid). Possible values are: cuboid, cylinder, cone or pyramid. It only applies to 3D bar charts.
- style (type: string). A list of properties in CSS format that only set the global properties of the chart. In order to customize the
different chart components you should use the associated chart methods.
- data (type: array),
The relevant CSS style type styles that one may apply globally to a chart include (where ‘*’ in this context stands for top, right, bottom or left).
- Size:
- width: the chart width.
- height: the chart height.
- Borders (individual borders are not supported):
- border: shorthand for border properties.
- border-color: sets the border color.
- border-style: sets the border line style.
- border-width: sets the border width.
- Display:
- float: it can be left, right and also center.
- margin: specifies all margin widths in one shot.
- margin-*: specifies one margin at a time.
- padding: specifies all padding widths in one shot.
- padding-*: specifies one padding at a time.
- position: absolute or relative.
- top: distance from the top for absolutely positioned charts.
- left: distance from the left for absolutely positioned charts.
Let us start by a simple example that will generate a plain column chart with all options left to their default values:
<?php /** * This sample script inserts a basic column chart */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf //insert a basic column bar chart $data = array( 'series' => array('First series', 'Second series'), 'Category 1' => array(20,40), 'Category 2' => array(30,10), 'Category 3' => array(12.5, 54), ); $doc->chart('column', array('data' => $data)); //include in the render method the path where you want your document to be saved $doc->render('basic_column_chart' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'basic_column_chart' . $format . '">Download document</a>';
We could customize its positioning, size and borders by just adding the required style information:
<?php /** * This sample script inserts a basic column chart */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf //insert a basic column bar chart $data = array( 'series' => array('First series', 'Second series'), 'Category 1' => array(20,40), 'Category 2' => array(30,10), 'Category 3' => array(12.5, 54), ); $doc->paragraph()->style('text-align: center') ->chart('column', array('data' => $data))->style('border: 1pt solid #777; width: 12cm; height: 9cm; padding: 0.2cm'); //include in the render method the path where you want your document to be saved $doc->render('basic_column_chart_2' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'basic_column_chart_2' . $format . '">Download document</a>';
Beware that currently the support for styling in Word and RTF is somehow limited, so if those are your target formats and you need to style the chart bounding box we recommend to use a wrapping table or textbox.
Chart data
If you need to customize further your data point chart styles you may use the chartData method.
Its public API is given by:
Signature
public chartData ($data [, $dataPointStyles])
Parameters
- data (type: array),
it can be an array with different formats:- pie and donut charts:
array(
‘category_1’ => 3,
‘category_2’ => 5,
‘category_3’ => 4.3,
) - bar, column, area , line, scatter, (filled-)radar and column-line charts:
array(
‘series’ => array(‘series_1’, ‘series_2’),
‘category_1’ => array(20,40),
‘category_2’ => array(30,10),
‘category_3’ => array(12.5, 54),
) - bubble charts:
array(
array(2, 5 7),
array(4.3, 12, 3.5),
array(6, 3, 5),
)
- pie and donut charts:
- $dataPointStyles (type: array). An array of arrays each of them with the following keys and values:
- fill-color (type: string). The data point color in hexadecimal format.
- opacity (type: string, default: 100%), specifies the fill color opacity as a percentage.
- stroke (type: string, default: solid). It can be none, solid or dash.
- stroke-width (type: string), specifies the line width.
- stroke-color (type: string), specifies the line color in hexadecimal format.
- stroke-opacity (type: string, default: 100%), specifies the line color opacity as a percentage.
- stroke-linejoin (type: string, default: round). Possible values are: round, bevel, middle, miter or none.
- stroke-linecap (type: string, default: butt). Possible values are: butt, round or squared.
- solid-type (type: string, default: cuboid). Possible values are: cuboid, cylinder, cone or pyramid. It only applies to 3D bar charts.
Following with our previous example we may change the data styles as follows:
<?php /** * This sample script inserts a custom column chart */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf //insert a custom column bar chart $data = array( 'series' => array('First series', 'Second series'), 'Category 1' => array(20,40), 'Category 2' => array(30,10), 'Category 3' => array(12.5, 54), ); $dataStyles = array( array( 'fill-color' => '#b70000', 'stroke' => 'solid', 'stroke-color' => '#660000', 'stroke-width' => '2pt', ), array( 'fill-color' => '#0000b7', 'stroke' => 'solid', 'stroke-color' => '#000066', 'stroke-width' => '2pt', ), ); $doc->paragraph()->style('text-align: center') ->chart('column')->style('width: 12cm; height: 9cm;') ->chartData($data, $dataStyles); //include in the render method the path where you want your document to be saved $doc->render('custom_column_chart' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'custom_column_chart' . $format . '">Download document</a>';
Chart legend
In order to add a legend to our chart one should make use of the chartLegend method which public API is given by:
Signature
public chartLegend ([$options])
Parameters
- $options (type: array). This array has the following available keys and values:
- legend-position (type: string). Possible values are: top, right, bottom or left.
- color (type: string). The legend font color in hexadecimal format.
- font-family (type: string). The legend text font family.
- font-size (type: string). The legend text font size in points, e.g. 11pt.
- font-weight (type: string, default: normal). The legend text font weight: normal or bold.
- font-style (type: string, default: normal). The legend text font style: normal or italic.
- fill-color (type: string). The data point color in hexadecimal format.
- opacity (type: string, default: 100%), specifies the fill color opacity as a percentage.
- stroke (type: string, default: solid). It can be none, solid or dash.
- stroke-width (type: string), specifies the line width.
- stroke-color (type: string), specifies the line color in hexadecimal format.
- stroke-opacity (type: string, default: 100%), specifies the line color opacity as a percentage.
- stroke-linejoin (type: string, default: round). Possible values are: round, bevel, middle, miter or none.
- stroke-linecap (type: string, default: butt). Possible values are: butt, round or squared.
<?php /** * This sample script inserts a column chart with a legend */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf //insert a column bar chart with a legend $data = array( 'series' => array('First series', 'Second series'), 'Category 1' => array(20,40), 'Category 2' => array(30,10), 'Category 3' => array(12.5, 54), ); $doc->paragraph()->style('text-align: center') ->chart('column', array('data' => $data))->style('width: 14cm; height: 9cm; padding: 0.2cm') ->chartLegend(); //include in the render method the path where you want your document to be saved $doc->render('legend_column_chart' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'legend_column_chart' . $format . '">Download document</a>';
You may further customize the display properties of the legend with the available option parameters, for example, in order to have the legend positiones in the top and with a border we should run the following code:
<?php /** * This sample script inserts a column chart with a custom legend */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf //insert a column bar chart with a custom legend $data = array( 'series' => array('First series', 'Second series'), 'Category 1' => array(20,40), 'Category 2' => array(30,10), 'Category 3' => array(12.5, 54), ); $doc->paragraph()->style('text-align: center') ->chart('column', array('data' => $data))->style('width: 12cm; height: 10cm; padding: 0.2cm') ->chartLegend(array('legend-position' => 'top', 'stroke' => 'solid', 'stroke-color' => '#cccccc')); //include in the render method the path where you want your document to be saved $doc->render('custom_legend_column_chart' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'custom_legend_column_chart' . $format . '">Download document</a>';
Chart axis
You may also customize all chart axis: x, y and z (in 3D charts) with the help of the chartAxis method which public API is given by:
Signature
public chartAxis ($axis [, $options])
Parameters
- $axis (type: string). Possible values are: x, y or z.
- $options (type: array).
This array has the following available keys and values:- visible (type: boolean, default: true). If true the axis is shown.
- logarithmic (type: boolean, default: false). If true the axis is shown with a logarithmic scale.
- font-color (type: string). The axis font color in hexadecimal format.
- font-family (type: string). The axis text font family.
- font-size (type: string). The axis text font size in points, e.g. 11pt.
- axis-position (type: mixed, default: start). It can be start (default), end or a numeric value dictating where the perpendicular axis should cross. In the case of the y-axis it refers to the category, i.e. 1 before the first category, 2 behind the second and so long so forth.
- minimum (type: float), specifies the minimum value of an axis.
- maximum (type: float), specifies the maximum value of an axis.
- label-arrangement (type: string). Possible values are: side-by-side, stagger-even or stagger-odd.
- display-label (type: boolean, default: true). If true displays the axis label.
- axis-label-position (type: string, default: near-axis). Possible values are: near-axis, near-axis-other-side, outside-end or outside-start.
- reverse-direction (type: boolean, default: false). If true reverses the axis direction.
- text-overlap (type: boolean, default: false). It specifies whether axis labels may overlap each other.
- line-break (type: boolean, default: true). It specifies whether text wrapping for axis labels is allowed.
- stroke (type: string, default: solid). It can be none, solid or dash.
- stroke-width (type: string), specifies the line width.
- stroke-color (type: string), specifies the line color in hexadecimal format.
- stroke-opacity (type: string, default: 100%), specifies the line color opacity as a percentage.
- stroke-linejoin (type: string, default: round). Possible values are: round, bevel, middle, miter or none.
- stroke-linecap (type: string, default: butt). Possible values are: butt, round or squared.
- interval-major (type: float), specifies the separation between major intervals within an axis.
- interval-minor-divisor (type: integer), specifies the number of divisions between to major interval lines.
- tick-marks-major-inner (type: boolean, , default: false). If true it shows inner major tick marks.
- tick-marks-minor-inner (type: boolean, , default: false). If true it shows inner minor tick marks.
- tick-marks-major-outer (type: boolean, , default: false). If true it shows outer major tick marks.
- tick-marks-minor-outer (type: boolean, , default: false). If true it shows outer minor tick marks.
For instance, if we want to customize the minimum and maximun values of the y axis and change the colors of the x and y axis lines, one should do the following:
<?php /** * This sample script inserts a column chart with a custom legend and axis */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf //insert a column bar chart with a custom legend and axis $data = array( 'series' => array('First series', 'Second series'), 'Category 1' => array(20,40), 'Category 2' => array(30,10), 'Category 3' => array(12.5, 54), ); $doc->paragraph()->style('text-align: center') ->chart('column')->style('width: 12cm; height: 10cm; padding: 0.2cm') ->chartData($data) ->chartLegend(array('legend-position' => 'top', 'stroke' => 'solid', 'stroke-color' => '#cccccc')) ->chartAxis('y', array('maximum' => 120, 'minimum' => 5, 'stroke-color' => '#b70000', 'stroke-width' => '2pt')) ->chartAxis('x', array('stroke-color' => '#b70000', 'stroke-width' => '2pt')); //include in the render method the path where you want your document to be saved $doc->render('axis_legend_column_chart' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'axis_legend_column_chart' . $format . '">Download document</a>';
Chart grid
If the default chart grid does not cover your needs you may use the chartGrid to customize the major as well as minor grid lines for the differents x, y and z axis (this last one only applicable to 3D charts).
Its public API is given by:
Signature
public chartGrid ([$axis [, $type [, $options]]])
Parameters
- $axis (type: string, default: x). Possible values are: x, y or z.
- $type (type: string, default: major). Grid type. Possible values are: major or minor.
- $options (type: array).
This array has the following available keys and values:- stroke (type: string, default: solid). It can be none, solid or dash.
- stroke-width (type: string, default: 2pt), specifies the line width. The default values are: 0.75pt for major grids and 0.5pt for minor grids.
- stroke-color (type: string), specifies the line color in hexadecimal format. For major grids the default is #d9d9d9 and #f0f0f0 for minor grids.
- stroke-opacity (type: string, default: 100%), specifies the line color opacity as a percentage.
- stroke-linejoin (type: string, default: round). Possible values are: round, bevel, middle, miter or none.
- stroke-linecap (type: string, default: butt). Possible values are: butt, round or squared.
If, for example we would like to include the minor grid lines for the x axis in our last example we would only need to make a simple call to this method:
<?php /** * This sample script inserts a column chart with a custom legend and axis and a minor grid */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf //insert a column bar chart with a custom legend and axis and a minor grid $data = array( 'series' => array('First series', 'Second series'), 'Category 1' => array(20,40), 'Category 2' => array(30,10), 'Category 3' => array(12.5, 54), ); $doc->paragraph()->style('text-align: center') ->chart('column')->style('width: 12cm; height: 10cm; padding: 0.2cm') ->chartData($data) ->chartLegend(array('legend-position' => 'top', 'stroke' => 'solid', 'stroke-color' => '#cccccc')) ->chartAxis('y', array('maximum' => 120, 'minimum' => 5, 'stroke-color' => '#b70000', 'stroke-width' => '2pt')) ->chartAxis('x', array('stroke-color' => '#b70000', 'stroke-width' => '2pt')) ->chartGrid('x', 'minor'); //include in the render method the path where you want your document to be saved $doc->render('grid_legend_column_chart' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'grid_legend_column_chart' . $format . '">Download document</a>';
Chart components: wall and floor
With the help of the charComponent one may customize the so called chart wall, i.e. the back of the chart plot area, and in 3D charts the chart floor.
Its public API is given by:
Signature
public chartComponent ([$component [, $options]])
Parameters
- $component (type: string, default: wall). Component type. Possible values are: wall or floor.
- $options (type: array).
This array has the following available keys and values:- fill-color (type: string). The data point color in hexadecimal format.
- opacity (type: string, default: 100%), specifies the fill color opacity as a percentage.
- stroke (type: string, default: solid). It can be none, solid or dash.
- stroke-width (type: string), specifies the line width.
- stroke-color (type: string), specifies the line color in hexadecimal format.
- stroke-opacity (type: string, default: 100%), specifies the line color opacity as a percentage.
- stroke-linejoin (type: string, default: round). Possible values are: round, bevel, middle, miter or none.
- stroke-linecap (type: string, default: butt). Possible values are: butt, round or squared.
If, for example we would like to change the default wall and floor chart colors of the 3D version of the previous chart we need to:
<?php /** * This sample script inserts a column bar chart with custom wall and floor components */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf //insert a column bar chart with custom wall and floor components $data = array( 'series' => array('First series', 'Second series'), 'Category 1' => array(20,40), 'Category 2' => array(30,10), 'Category 3' => array(12.5, 54), ); $doc->paragraph()->style('text-align: center') ->chart('3Dcolumn')->style('width: 12cm; height: 10cm; padding: 0.2cm') ->chartData($data) ->chartLegend(array('legend-position' => 'top', 'stroke' => 'solid', 'stroke-color' => '#cccccc')) ->chartComponent('wall', array('fill-color' => '#ffff99')) ->chartComponent('floor', array('fill-color' => '#f0f0f0')); //include in the render method the path where you want your document to be saved $doc->render('wall_floor_column_chart' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'wall_floor_column_chart' . $format . '">Download document</a>';
3D Transformations
Whenever using 3D charts one may prefer a different perspective or view angle that the one offered by default by Docxpresso. If that is the case we may use the chart3DTransform method to customize the 3D display.
Its public API is given by:
Signature
public chart3DTransform ([$options])
Parameters
- $options (type: array).
This array has the following available keys and values:- rotate-x (type: integer, default: 11 ). Rotation angle respect the x-axis.
- rotate-y (type: integer, default: 25 ). Rotation angle respect the y-axis.
- rotate-z (type: integer, default: 5 ). Rotation angle respect the z-axis.
- perspective (type: integer, default: 20 ). Given as a percentage.
- right-angled-axes (type: boolean, , default: 20). If true the rotate-z parameter is ignored.
The following code serves as an example of this method capabilities:
<?php /** * This sample script modifies the default 3d view of a chart */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf //insert a 3D column bar chart and change its angle and perspective $data = array( 'series' => array('First series', 'Second series'), 'Category 1' => array(20,40), 'Category 2' => array(30,10), 'Category 3' => array(12.5, 54), ); $doc->paragraph()->style('text-align: center') ->chart('3Dcolumn')->style('width: 12cm; height: 11cm; padding: 0.2cm') ->chartData($data) ->chartLegend(array('legend-position' => 'bottom')) ->chart3dTransform(array('right-angled-axes' => false, 'perspective' => 15, 'rotate-y' => 30)); //include in the render method the path where you want your document to be saved $doc->render('transform_3D_column_chart' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'transform_3D_column_chart' . $format . '">Download document</a>';
Notice that the rendering of slanted lines in RTF format is not as good as expected so try to set the right-angled-axes option to true for this output format.
Let us finish this section by offering a few other examples with other chart types.
Miscellaneous examples
Pie charts
<?php /** * This sample script inserts a 3D pie chart */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf //insert a 3D pie chart $data = array( 'category_1' => 3, 'category_2' => 5, 'category_3' => 4.3, ); $chartProperties = array('data-label-number' => 'percentage', 'label-position' => 'center'); $doc->paragraph()->style('text-align: center') ->chart('3DPie', array('data' => $data, 'chart-properties' => $chartProperties)) ->style('width: 14cm; height: 12cm') ->chartLegend(); //include in the render method the path where you want your document to be saved $doc->render('pie_chart' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'pie_chart' . $format . '">Download document</a>';
Donut charts
<?php /** * This sample script inserts a exploded donut chart */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.odt';//.pdf, .doc, .docx, .odt, .rtf //insert a donut chart $data = array( 'category_1' => 3, 'category_2' => 5, 'category_3' => 4.3, ); $chartProperties = array('data-label-number' => 'percentage', 'label-position' => 'center', 'pie-offset' => 20); $doc->paragraph()->style('text-align: center') ->chart('donut', array('data' => $data, 'chart-properties' => $chartProperties)) ->style('width: 14cm; height: 12cm') ->chartLegend(); //include in the render method the path where you want your document to be saved $doc->render('donut_chart' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'donut_chart' . $format . '">Download document</a>';
Area charts
<?php /** * This sample script inserts an area chart */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.odt';//.pdf, .doc, .docx, .odt, .rtf //insert an area chart $data = array( 'series' => array('First series', 'Second series'), 'Category 1' => array(20,40), 'Category 2' => array(30,10), 'Category 3' => array(12.5, 54), ); $dataStyles = array( array( 'opacity' => '65%', ), array( 'opacity' => '65%', ), ); $doc->paragraph()->style('text-align: center') ->chart('area')->style('width: 12cm; height: 9cm;') ->chartData($data, $dataStyles) ->chartLegend(); //include in the render method the path where you want your document to be saved $doc->render('area_chart' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'area_chart' . $format . '">Download document</a>';
The RTF format has no support for transparencies in charts.
Line charts
<?php /** * This sample script inserts a 3D line chart */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.odt';//.pdf, .doc, .docx, .odt, .rtf //insert a 3D line chart $data = array( 'series' => array('First series', 'Second series'), 'Category 1' => array(20,40), 'Category 2' => array(30,10), 'Category 3' => array(12.5, 54), ); $dataStyles = array( array( 'opacity' => '85%', ), array( 'opacity' => '85%', ), ); $doc->paragraph()->style('text-align: center') ->chart('3Dline')->style('width: 12cm; height: 9cm;') ->chartData($data, $dataStyles) ->chartLegend(); //include in the render method the path where you want your document to be saved $doc->render('line_chart' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'line_chart' . $format . '">Download document</a>';
Radar charts
<?php /** * This sample script inserts a radar chart */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.odt';//.pdf, .doc, .docx, .odt, .rtf //insert a radar chart $data = array( 'series' => array('First', 'Second', 'Third'), 'Cat 1' => array(20,40, 60), 'Cat 2' => array(30,10, 10), 'Cat 3' => array(12.5, 54), 'Cat 4' => array(50, 20, 60), 'Cat 5' => array(90, 54, 12), ); $doc->paragraph()->style('text-align: center') ->chart('radar')->style('width: 12cm; height: 9cm;') ->chartData($data) ->chartLegend() ->chartGrid('y', 'minor'); //include in the render method the path where you want your document to be saved $doc->render('radar_chart' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'radar_chart' . $format . '">Download document</a>';
Bubble charts
<?php /** * This sample script inserts a bubble chart */ require_once 'pathToDOCXPRESSO/CreateDocument.inc'; $doc = new Docxpresso\CreateDocument(); $format = '.odt';//.pdf, .doc, .docx, .odt, .rtf //insert a bubble chart //each data point array is given by (y, x, size) in pdf, odt and ref //or (x, y, size) in doc format $data = array( array(40, 10, 4), array(50, 20, 3), array(12, 30, 9), array(30, 40, 2), array(22, 50, 7), ); $doc->paragraph()->style('text-align: center') ->chart('bubble')->style('width: 12cm; height: 9cm;') ->chartData($data) ->chartGrid('y', 'minor'); //include in the render method the path where you want your document to be saved $doc->render('bubble_chart' . $format); //echo a link to the generated document echo 'You may download the generated document from the link below:<br/>'; echo '<a href="' . 'bubble_chart' . $format . '">Download document</a>';
Beware that the Word (.doc) format interchanges the x and y axis with respect the PDF, ODT and RTF formats.