Forum


Replies: 2   Views: 810
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 netsolution  · 26-08-2020 - 14:23

Hello,

I try to change the colors in a chart and have added the following code (according to documentation):

 

$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(
        'valueRgbColors' =>  array(array('4C0099', 'FF0000', 'FF8800','00CC00')),
        'serRgbColors' =>  array(array('4C0099', 'FF0000', 'FF8800','00CC00')),
    )
);

 

But the chart is always displayed in the blue scheme (have also tried to use only serRgbColors or valueRgbColors, but no change)

What is wrong here?

Thanks!

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.

Posted by netsolution  · 26-08-2020 - 16:28

Ok then the problem is that I am using 7.5 (see my other post), need to upgrade ;-)

Thanks!