Forum


Replies: 2   Views: 1572
Chart theme colors
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  · 26-08-2020 - 14:51

Hello,

The core you are running has some issues; instead of:

'theme' => array(
  'valueRgbColors' =>  array(array('4C0099', 'FF0000', 'FF8800','00CC00')),
  'serRgbColors' =>  array(array('4C0099', 'FF0000', 'FF8800','00CC00')),
)

This is the correct structure to apply custom colors to bar, col and similar charts (other charts such as pie use other structure you can read in the included samples):

'theme' => array(
    'serRgbColors' => array(null, 'FF00FF', '00FFFF'),
    'valueRgbColors' => array(
        array('FF0000'),
        null,
        array(null, null, '00FF00'),
        null,
    ),
)

We have run the following code and the custom colors are set correctly:

$docx = new CreateDocx();

$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,
    'type' => 'barChart',
    'color' => '3',
    'chartAlign' => 'center',
    'sizeX' => '14',
    'sizeY' => '14',
    'legendPos' => 'b',
    'legendOverlay' => '0',
    'border' => '1',
    'hgrid' => '10',
    'vgrid' => '0',
    'groupBar' => 'stacked',
    'theme' => array(
        'serRgbColors' => array(null, 'FF00FF', '00FFFF'),
        'valueRgbColors' => array(
            array('FF0000'),
            null,
            array(null, null, '00FF00'),
            null,
        ),
    ),
);
$docx->addChart($paramsChart);

$docx->createDocx('output');

 We have opened the output with MS Word 2007 to MS Word 2019 and LibreOffice 5, 6 and 7 and in all cases the chart is correct (custom colors are set correctly).

Theme charts are available since phpdocx 9.5 in Premium licenses, please check you are not using an old version of phpdocx. We recommend you to check the samples included in the examples/Core/addChart folder in the packages, for example sample_17.php that generates a chart setting both serRgbColors and valueRgbColors properties.

Regards.