Forum


Replies: 1   Views: 157
Barchat multiple values, multiple columns
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 deweb  · 19-07-2024 - 10:08

Good morning

I'm looking to make a graph like this (see the image link) ?
https://www.imghippo.com/i/BfM561721383656.jpg

Multiple values, multiple columns.Is it possible ? 

I searched through the examples and didn't find any solutions.

Thanks in advance

Posted by admin  · 19-07-2024 - 18:11

Hello,

We have done some tests and we are unable to generate a column chart mixing clustered and stacked columns using MS Word.

The supported column types are the following:

'groupBar' (clustered, stacked, percentStacked)
 
but it doesn't seem possible to mix them in the same chart.
 
Creating a comboChart with a clustered column chart and a stacked column chart, the columns overlap, so another chart type should be used to display the chart correctly, such as a line chart (https://answers.microsoft.com/en-us/msoffice/forum/all/is-it-possible-to-both-cluster-and-stack-in-column/9c9e8174-7b3b-49fc-948b-54b73c494e06).

The following sample included in the package (sample_14.php) creates a combo chart adding column and line charts:

require_once 'classes/CreateDocx.php';

$docx = new CreateDocx();

$docx->addText('We will now add a combo chart to the Word document:');

// generate the first chart as WordFragment
$chartFragment = new WordFragment($docx);

$data = array(
    'legend' => array('Series 4', 'Series 5'),
    'data' => array(
        array(
            'name' => 'data A',
            'values' => array(40, 30),
        ),
        array(
            'name' => 'data B',
            'values' => array(50, 60),
        ),
        array(
            'name' => 'data C',
            'values' => array(10, 70),
        ),
        array(
            'name' => 'data D',
            'values' => array(20, 60),
        ),
    ),
);
$paramsChart = array(
    'data' => $data,
    'type' => 'lineChart',
    'symbol' => 'none',
    'smooth' => true,
    'returnChart' => true,
);
$comboChart = $chartFragment->addChart($paramsChart);

$data = array(
    'legend' => array('Series 1', 'Series 2', 'Series 3'),
    'data' => array(
        array(
            'name' => 'data 1',
            'values' => array(10, 7, 5),
        ),
        array(
            'name' => 'data 2',
            'values' => array(20, 60, 3),
        ),
        array(
            'name' => 'data 3',
            'values' => array(50, 33, 7),
        ),
        array(
            'name' => 'data 4',
            'values' => array(25, 0, 14),
        ),
    ),
);
$paramsChart = array(
    'data' => $data,
    'comboChart' => $comboChart, // set the first chart to be added
    'type' => 'colChart',
    'color' => '2',
    'perspective' => '10',
    'rotX' => '10',
    'rotY' => '10',
    'chartAlign' => 'center',
    'sizeX' => '10',
    'sizeY' => '10',
    'legendPos' => 'none',
    'legendOverlay' => '0',
    'border' => '1',
    'hgrid' => '3',
    'vgrid' => '0',
    'groupBar' => 'clustered',
);
$docx->addChart($paramsChart);

$docx->createDocx('example_addChart_14');

We recommend you create a combo chart for this task. If you generate with MS Word a sample chart with the exact output you need to get using only column charts, please send it to contact[at]phpdocx.com and we'll check it.

Regards.