addTemplateChart

Replaces a PHPDocX placeholder variable by a chart.

PRO, PRO+ and CORPORATE PHPDocX >= 1.7

Description

public addTemplateChart (string $variableName, array $chartData)

This method searches for all the ocurrences of the variable ($variableName$) and replaces them with a chart.

Unless you set specifically a template symbol with the setTemplateSymbol method, the variable name must be surrounded by dollar signs whitin the template.

Parameters

variableName

This is the name of the variable associated with the placeholder image. This variable should be inserted surrounded by dollar signs (or the chosen template symbol) in the Word template.

chartData

This array should include all the required chart data. Please, refer to the addChart method for further parametrization details.

Return values

Void.

Code samples

Example #1: replaces the $PIECHART$ variable by a pie chart


require_once 'classes/CreateDocx.inc';

$docx = new CreateDocx();

$docx->addTemplate('TemplateChart.docx');

$legends = array(
    'legend1' => array(10, 11, 12),
    'legend2' => array(30, 21, 12),
    'legend3' => array(40, 41, 42)
);

$chartData =
    array(
        'data' => $legends,
        'type' => 'pie3DChart',
        'title' => 'Title',
        'cornerX' => 20,
        'cornerY' => 20,
        'cornerP' => 30,
        'color' => 2,
        'textWrap' => 0,
        'sizeX' => 10,
        'sizeY' => 10,
        'jc' => 'right',
        'showPercent' => 1,
        'font' => 'Times New Roman'
    );

$docx->addTemplateChart('PIECHART', $paramsChart);

$docx->createDocx('template_chart.docx');

The resulting Word document looks like (download .docx file):

Change log

  • Available since 1.7