Forum


Replies: 4   Views: 1300
Change values of multiple graphs in a template
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 12-05-2021 - 16:01

Hello,

replaceChartData is the method to be used when replacing chart values. Please note that this method replaces the exact number of values of the chart; extra values can't be added to a chart using this method, the method only replaces values.

About your question, replaceChartData replaces values by order using the data array:

data

The keys are the numbers of the charts to replace and the values are arrays of data as described in the addChart method.

For example, if we change the included sample replaceChartData/sample_1.php to replace only the second array we use the following code:

$data = array();

$data[1] = array(
    'title' => 'Other title',
    'legends' => array(
        'legend 1',
        'legend 2',
        'legend 3',
    ),
    'categories' => array(
        'other cat 1',
        'other cat 2',
        'other cat 3',
        'other cat 4',
    ),
    'values' => array(
        array(25, 10, 5),
        array(20, 5, 4),
        array(15, 0, 3),
        array(10, 15, 2),
    ),
);

Setting $data[1], the values and other information in the second chart (key 0 is the first chart, key 1 is the second chart and so on) will be replaced by the new contents.

For example, if you want to replace the first, third and fourth charts you need to use:

$data = array();

$data[0] = array(
...
);
$data[2] = array(
...
);
$data[3] = array(
...
);

Regards.