Forum


Replies: 2   Views: 3068
Axis labels overlay on top of axis values - which parameter is wrong
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 andrzej.morun  · 18-12-2016 - 17:53

I use Advanced Version of phpdocx 6.5.

I have sam problem with layouting charts.

1) I'm adding a 2D column chart to my document but the axis labels always seem to overlay on top of the values display along on the X and Y axis.

2) Inspite of I set parametr  'legendpos' => 'none' the legend on the chart stiil is displayed

What I'm doing wrong?

Sample code:

$docx = new CreateDocxFromTemplate ( 'template.docx' );
$data = array(
    'legend' => array(''),
    'January' => array(10),
    'February' => array(17),
    'March' => array(25),
    'April' => array(9)
);

    $paramsChart = array (
            'data' => $data,
            'type' => 'colChart',
            'title' => 'Sales',
            'color' => 2,
            'sizeX' => 10,
            'sizeY' => 6,
            'font' => 'Times New Roman',
            'legendpos' => 'none',
            'border' => 'none',
            'haxLabel' => 'Months',
            'haxLabelDisplay' => 'horizontal',
            'vaxLabel' => 'Sales [$]',
            'vaxLabelDisplay' => 'rotated',
            'hgrid' => 1,
            'vgrid' => 0,
            'chartAlign' => 'center',
            'showCategory' => false
            
    );

    $chart = new WordFragment ( $docx, 'document' );
    $chart->addChart ( $paramsChart );
$variables = array (
         'CHART1' => $chart
);
$docx->replaceVariableByWordFragment ( $variables, array (
        'type' => 'inline'
) );

$docx->addText('And now the same chart addChartMethod on $docx');
$docx->addChart($paramsChart);

 

Posted by admin  · 19-12-2016 - 08:28

Hello,

To hide the legend, please use legendPos (this is P, not p).

About the overlay of the axis title, phpdocx doesn't allow to control it and set it in the default position (may overlap the axis). To fix this, please edit the file CreateGraphic.inc and in the generateAXLABEL method add this tag:

<c:overlay val="0"/>

after </c:tx>.

This is the current method:

protected function generateAXLABEL($val = 'Axis title')
{
  $xml = '<' . CreateGraphic::NAMESPACEWORD . ':title><c:tx><c:rich>' .
                '__GENERATEBODYPR__<a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr>' .
                '<a:r><a:t>' . $val . '</a:t></a:r></a:p></c:rich></c:tx>' .
                '</' . CreateGraphic::NAMESPACEWORD . ':title>__GENERATEAX__';
  $this->_xmlChart = str_replace(
                '__GENERATEAX__', $xml, $this->_xmlChart
  );
}

And this is the method after adding the new tag:

protected function generateAXLABEL($val = 'Axis title')
{
  $xml = '<' . CreateGraphic::NAMESPACEWORD . ':title><c:tx><c:rich>' .
                '__GENERATEBODYPR__<a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr>' .
                '<a:r><a:t>' . $val . '</a:t></a:r></a:p></c:rich></c:tx><c:overlay val="0"/>' .
                '</' . CreateGraphic::NAMESPACEWORD . ':title>__GENERATEAX__';
  $this->_xmlChart = str_replace(
                '__GENERATEAX__', $xml, $this->_xmlChart
  );
}

We have added a task to add this change in the master branch of the library.

Regards.

Posted by andrzej.morun  · 19-12-2016 - 20:08

It's works great. Thank you.