Forum


Replies: 3   Views: 2666
Repeat x axis name in colchart
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 Samuel  · 17-02-2017 - 14:12

Hi,

I have a problem with a 'colChart'. There are 2 series of data, a variable number of values each. The problem is that some of the values names are the same, and as this names are the keys of a php array, they are overwritten.

An example:

$chart_data = array(
    'legend' => array(
        'Serie 1',
        'Serie 2'
    ),
    'E' => array($d1, $d2),
    'F' => array($d1, $d2),
    'M' => array($d1, $d2),
    'A' => array($d1, $d2),
    'M' => array($d1, $d2),
    'J' => array($d1, $d2),
    'J' => array($d1, $d2),
    'A' => array($d1, $d2),
    'S' => array($d1, $d2),
    'O' => array($d1, $d2),
    'N' => array($d1, $d2),
    'D' => array($d1, $d2),
);

'M', 'A' y 'J' are more than once, and that's a problem in PHP.

¿Is there any way to do it?

Thank you

Posted by admin  · 17-02-2017 - 14:40

Hello,

The current version of phpdocx uses array keys as data values, and as it's an associative array, these keys must be unique.

We send this request to the dev team. They'll generate a patch to allow adding repeated values. We'll update this topic with the patch and a simple sample.

Regards.

Posted by Samuel  · 17-02-2017 - 14:57

Ok, thank you. Meanwhile I'm adding spaces before and after existent keys:

while (isset($chart_data[$x_name])) {
    $x_name = " $x_name ";
}

$chart_data[$x_name] = ...

 

Posted by admin  · 20-02-2017 - 09:22

Hello,

phpdocx uses associative arrays as X name values, so you need to add unique values.

You can add empty spaces to repeat values, but if you need to use the exact name as axis, please edit the CreateBarChart.inc file and change these lines:

foreach ($this->values as $legend => $value) {
    if ($legend == 'legend') {
        continue;
    }
    $this->generatePT($num);
    $this->generateV($legend);
    $num++;
}

By a new code that uses other array value instead of key values. For example:

foreach ($this->values as $value) {
    if ($value['legend'] == 'legend') {
        continue;
    }
    $this->generatePT($num);
    $this->generateV($value['legend']);
    $num++;
}

You also need to change $this->values variable in this same file to storage the data values. So instead of settings legends as array key, you can use other array value to set legends.

We have added a task to consider adding these changes to a future release of the library, but the current version of phpdocx uses unique values as X axis names.

Regards,
phpdocx support team