Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error opening xlsx file with a bar chart #3397

Closed
2 tasks
Jeejaj opened this issue Feb 23, 2023 · 6 comments · Fixed by #3404
Closed
2 tasks

Error opening xlsx file with a bar chart #3397

Jeejaj opened this issue Feb 23, 2023 · 6 comments · Fixed by #3404
Labels

Comments

@Jeejaj
Copy link

Jeejaj commented Feb 23, 2023

This is:

  • a bug report

What is the expected behavior?

File should open with out any warnings and should display the bar chart with specified custom colors.

What is the current behavior?

File opens with a warning

report_warning

What are the steps to reproduce?

  $spreadsheet->setActiveSheetIndex($sheet_index);
  $sheet = $spreadsheet->getActiveSheet();
  $sheet->setTitle('Chart');
  $dataSeriesLabels = [
      new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Summary_report!$D$8', null, 1, [$report_config['legend'][2]['legend']], null, 'ff0000'),
      new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Summary_report!$D$9', null, 1, [$report_config['legend'][1]['legend']], null, '70ad47'),
      new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Summary_report!$D$10', null, 1, [$report_config['legend'][0]['legend']], null, 'ffff00'),
             ];
  $xAxisTickValues = [
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Summary_report!$E$7:$'.$col.'$7', null, $colNumber),
             ];
  $dataSeriesValues = [
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Summary_report!$E$8:$'.$col.'$8', null, $colNumber),
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Summary_report!$E$9:$'.$col.'$9', null, $colNumber),
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Summary_report!$E$10:$'.$col.'$10', null, $colNumber),
             ];     
 $series = new DataSeries(
                 DataSeries::TYPE_BARCHART, // plotType
                 DataSeries::GROUPING_STACKED, // plotGrouping
                 range(0, count($dataSeriesValues) - 1), // plotOrder
                 $dataSeriesLabels, // plotLabel
                 $xAxisTickValues, // plotCategory
                 $dataSeriesValues        // plotValues
             );
             $layout1 = new Layout();
             $layout1->setShowVal(TRUE);
             $plotArea = new PlotArea($layout1 , [$series]);
            
             $legend = new Legend(Legend::POSITION_BOTTOM, null, false);
             $title = new Title('Submission Report');
             $yAxisLabel = new Title('Count');
             $xAxisLabel = new Title('period');
             $yaxis = new Axis();
             $yaxis->setAxisOptionsProperties('low', null, null, null, null, null, 0, null, null, null);

//	Create the chart
             $chart = new Chart(
                 'chart1', // name
                 $title, // title
                 $legend, // legend
                 $plotArea, // plotArea
                 true, // plotVisibleOnly
                  'gap',// displayBlanksAs
                 $xAxisLabel , // xAxisLabel
                 $yAxisLabel,  // yAxisLabel
                 null,
                 $yaxis
             );
                                                                                                                                      

This above code results on the chart with specified custom color code, but the warning will be displayed during file opens.
If the last argument (color code) in the $dataSeriesLabels is not passed the warning will not appear but the chart displayed with different color.
The issue exist from 1.24.0v onwards.

What features do you think are causing the issue

  • Charts

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet - 1.27.1 (from 1.24.0 onwards)
php - 8.2

@Jeejaj Jeejaj changed the title Error opening .Xlsx file with bar chart. Getting warning message that we found a problem with some content in test.xlsx.. etc Error opening xlsx file with a bar chart Feb 23, 2023
@oleibman
Copy link
Collaborator

All of $report_config, $col, and $colNumber are undefined when they are first used in your code. Can you please tell me their values so that I can investigate further.

@Jeejaj
Copy link
Author

Jeejaj commented Feb 26, 2023

$report_config =
Array
(
    [legend] => Laminas\Config\Config Object
        (
            [allowModifications:protected] => 
            [data:protected] => Array
                (
                    [0] => Laminas\Config\Config Object
                        (
                            [allowModifications:protected] => 
                            [data:protected] => Array
                                (
                                    [days] => 0
                                    [time] => 10:00 AM
                                    [color] => Green
                                    [code] => #e3ffe6
                                    [legend] => On or before 10:00 AM ET on 1st business day
                                )

                            [skipNextIteration:protected] => 
                        )

                    [1] => Laminas\Config\Config Object
                        (
                            [allowModifications:protected] => 
                            [data:protected] => Array
                                (
                                    [days] => 1
                                    [time] => 10:00 AM
                                    [color] => Yellow
                                    [code] => #fff4d6
                                    [legend] => On or before 10:00 AM ET on 2nd business day (Grace Period)
                                )

                            [skipNextIteration:protected] => 
                        )

                    [2] => Laminas\Config\Config Object
                        (
                            [allowModifications:protected] => 
                            [data:protected] => Array
                                (
                                    [days] => 2
                                    [time] => 10:00 AM
                                    [color] => Red
                                    [code] => #ffe5e3
                                    [legend] => After 10:00 AM ET on 2nd business day, or Not submitted
                                )

                            [skipNextIteration:protected] => 
                        )

                    [include_weekends_and_holidays] => 1
                )

            [skipNextIteration:protected] => 
        )

)

$col = J;

$colNumber = 7;

@oleibman
Copy link
Collaborator

Thank you. I can now get the program to run, but ... I need the data on your Summary_report worksheet in order to populate the chart. It looks like I need cells D8-D10 and E7-J10.

@oleibman
Copy link
Collaborator

Never mind about the data, I can use some random numbers to investigate further.

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Feb 26, 2023
@Jeejaj
Copy link
Author

Jeejaj commented Feb 27, 2023

@oleibman This works fine in my environment. Thanks for your contribution.

@oleibman
Copy link
Collaborator

@Jeejaj Thank you for confirming. I will merge this change some time this week.

oleibman added a commit that referenced this issue Mar 2, 2023
* Misplaced Xml Writing Chart Label FillColor

Fix #3397. Move code to correct location.

* Update Issue3397Test.php

No need for spacing patch - just fix it now.

* Minor Fix

See discussion at bottom of PR #2856.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants