Forum


Replies: 1   Views: 2001
Issue with & in the array
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 dev@ram  · 12-09-2017 - 14:50

Hi,

I'm trying to create a doughnut chart but there is an issue.

The array structure given to  addChart() is shown below:

It seems the '&' in one of the keys corrupts the document (it's generated but the repair dialog shows on opening). Any idea how to fix this? (the chart generates if we remove that key)

Please help. We are using a paid version.

Array
(
    [data] => Array
        (

            [O&M SA] => Array
                (
                    [0] => 472
                )

             [All Others] => Array
                (
                    [0] => 850
                )

        )

    [type] => doughnutChart
    [color] => 18
    [sizeX] => 15
    [border] => 1
    [sizeY] => 12
    [chartAlign] => center
    [showPercent] => 1
    [font] => Arial
    [title] => Graph title
)

 

Posted by admin  · 12-09-2017 - 15:34

Hello,

You need to use the htmlentities function when you need to add a protected character such as & or <.

For example:

$data = array(
    htmlentities('data &1') => array(20),
    'data 2' => array(20),
    'data 3' => array(50),
    'data 4' => array(25),
    'data 5' => array(5),
);

$paramsChart = array(
    'data' => $data,
    'type' => 'doughnutChart',
    'showPercent' => true,
    'explosion' => 10,
    'holeSize' => 25,
    'sizeX' => 12,
    'sizeY' => 10,
    'chartAlign' => 'center',
    'color' => '2',
    'legendPos' => 'r',
    'legendOverlay' => true,
    'showTable' => true,
);
$docx->addChart($paramsChart);

Regards.