PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.35k stars 3.47k forks source link

Chart color scheme should be selected freely #563

Closed rf1234 closed 5 years ago

rf1234 commented 6 years ago

This is:

- [ ] a bug report
- [x ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

You should be able to use your own color scheme paticularly for charts.

What is the current behavior?

Currently only the standard Office color scheme is available making you charts look like everbody else's charts. The color scheme is hard coded.

What are the steps to reproduce?

Also here: I had to use a hard coded solution to get this fixed. I found the hex color scheme in file "Theme.php" and replaced it with my own.

<?php
//Roland Finke: MS Office standard color scheme
    private static $colourScheme = [
        'dk2' => '1F497D',
        'lt2' => 'EEECE1',
        'accent1' => '4F81BD',
        'accent2' => 'C0504D',
        'accent3' => '9BBB59',
        'accent4' => '8064A2',
        'accent5' => '4BACC6',
        'accent6' => 'F79646',
        'hlink' => '0000FF',
        'folHlink' => '800080'
    ];

Which versions of PhpSpreadsheet and PHP are affected?

jeromeWeissmann commented 6 years ago

+1 for this, i'm lookin for the same thing

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue for you, please try to help by debugging it further and sharing your results. Thank you for your contributions.

kifni41 commented 6 years ago

@rf1234 hi, you can actually set the chart fillcolor individually when you're defining plotLabel and plotValues as DataSeriesValues

$dataSeriesLabels = [

new PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1), null, 1, [], null, '000000'), 

new PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$E$1), null, 1, [], null, 'FFFFFF'), 

];

$dataSeriesValues = [

new PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$5), null, 1, [], null, '000000'), 

new PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$E$5), null, 1, [], null, 'FFFFFF'), 

]

I never use the custom color feature till now for my work, but after read your question and decide to check the source code, and i found that we actually can set the color manually. I just tested to set the color manualy and it's works.

Hope it helps, unless what you want's passing and array of color schemes and passing as parameter when creating chart.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue for you, please try to help by debugging it further and sharing your results. Thank you for your contributions.

oleibman commented 3 months ago

Theme now has setThemeColor and setThemeColorName methods.