Forum


Replies: 7   Views: 161
Docxprem - custom colors for charts

Posted by dev@ram  · 01-07-2020 - 10:15

Hi guys,

I have tried to follow the docs for adding custom colors to charts but they are a bit incomplete: https://www.phpdocx.com/api-documentation/word-content/add-chart-Word-document-with-PHP

This part here:

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

I am trying to set the colors for a pie chart - 2 different colors for 2 series - how would i do that?

Regards

Posted by admin  · 01-07-2020 - 10:29

Hello,

Please check the following sample included in the package: examples/Core/addChart/sample_18.php that sets custom colors for a pie chart, you can customize them setting valueRgbColors (as pie charts use a single serie with values instead of mutiple series with values) in the same order than the values have been added:

$data = array(
    'data' => array(
        array(
            'name' => 'data 1',
            'values' => array(10),
        ),
        array(
            'name' => 'data 2',
            'values' => array(20),
        ),
        array(
            'name' => 'data 3',
            'values' => array(50),
        ),
        array(
            'name' => 'data 4',
            'values' => array(25),
        ),
    ),
);

$paramsChart = array(
    'data' => $data,
    'type' => 'pieChart',
    'color' => 3,
    'sizeX' => 10,
    'sizeY' => 5,
    'chartAlign' => 'center',
    'theme' => array(
        'valueRgbColors' => array(
            array('99C099', '678CB3', 'ACA42E'),
        ),
    ),
);
$docx->addChart($paramsChart);

Using a Premium license, in this same folder (Core/addChart) you can find 21 samples that illustrate how to use options of the addChart method.

Regards.

Posted by dev@ram  · 08-07-2020 - 10:28

Thank you :).

I have one more question though :).

Can we have labels with 1 decimal in the charts? if it's not a whole number i.e 7.2, it works but if we have 7.0 it displays 7.

Any workaround for this?

Regards,

Posted by admin  · 08-07-2020 - 10:51

Hello,

MS Word removes .0 values from data tables. Using the formatCode option (examples/Core/addCharts/sample_16.php) you can force a format code but only to axis values.

Regards.

Posted by dev@ram  · 29-07-2020 - 09:09

Hi guys,

First of all, thanks for all your help :).

I have one more question:

Is it possible to have superscripts in chart labels?

at the moment is showing up like this: TEST® , is it possible to have it superscript?

Thank you in advance

Posted by admin  · 29-07-2020 - 09:45

Hello,

addChart allows applying the following styles to the title:

*  'stylesTitle' (array)
     *      'bold' (boolean)
     *      'color' (ffffff, ff0000...)
     *      'font' (Arial, Times New Roman...)
     *      'fontSize' (8, 9, 10, ...) size as drawing content (10 to 400000). 1420 as default
     *      'italic' (boolean)

superscript and subscript styles are not supported yet. The same styles are applied to the whole title. We have moved the request to the dev team to add suport.

Regards.

Posted by dev@ram  · 29-07-2020 - 09:58

Great :).

What about the labels though? in this case the "name"?

$data = array(
    'data' => array(
        array(
            'name' => 'data 1',
            'values' => array(10),
        ),
        array(
            'name' => 'data 2',
            'values' => array(20),
        ),
        array(
            'name' => 'data 3',
            'values' => array(50),
        ),
        array(
            'name' => 'data 4',
            'values' => array(25),
        ),
    ),
);

 

Posted by admin  · 29-07-2020 - 11:53

Hello,

Labels can't be styled using subscript or superscripts styles. On https://www.phpdocx.com/api-documentation/word-content/add-chart-Word-document-with-PHP you can read the support styles and options when adding a chart.

Regards.