Forum


Replies: 1   Views: 193
Combine 2 charts
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  · 10-06-2024 - 14:45

Hello,

Yes, you can generate combo charts using comboChart and returnChart options:

Chart to add as a combo chart. Use with the returnChart option. Global styles and properties are shared with the base chart. For bar, col, line, area, and radar charts.

The following sample included in the package (examples/addChart/sample_14.php) generates a combo chart with col and line chart types:

// 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');

Regards.