Forum


Replies: 1   Views: 466
Creating a bar chart
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  · 07-09-2023 - 10:27

Hello,

Please note there's no barDirection option in the addChart method, you need to set the type option. Please check the available documentation on addChart.

If you need to create a column chart you need to set type as colChart. For example, using the same styles from your code:

$data = array(
    'legend' => array('Legend 1', 'Legend 2', 'Legend 3'),
    'data' => array(
        array(
            'name' => 'data 1',
            'values' => array(10, 20, 5),
        ),
        array(
            'name' => 'data 2',
            'values' => array(20, 60, 3),
        ),
        array(
            'name' => 'data 3',
            'values' => array(50, 33, 7),
        ),
    ),
);
$paramsChart = array(
    'data' => $data,
    'type' => 'colChart',
    'color' => '3',
    'perspective' => '10',
    'rotX' => '10',
    'rotY' => '10',
    'chartAlign' => 'center',
    'sizeX' => '10',
    'sizeY' => '10',
    'legendPos' => 'b',
    'legendOverlay' => '0',
    'border' => '1',
    'hgrid' => '3',
    'vgrid' => '0',
    'groupBar' => 'stacked',
);
$docx->addChart($paramsChart);

Regards.