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.