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

32_Chart_read_write.php modifies Scatter charts in odd ways #2762

Closed
bridgeplayr opened this issue Apr 21, 2022 · 5 comments · Fixed by #2828
Closed

32_Chart_read_write.php modifies Scatter charts in odd ways #2762

bridgeplayr opened this issue Apr 21, 2022 · 5 comments · Fixed by #2828
Labels

Comments

@bridgeplayr
Copy link

This is:

- [x] a bug report
- [ ] 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?

saved Excel Scatter Chart xlsx templates should mirror the template with no changes - (focused on Scatter Chart templates ONLY)

What is the current behavior?

Saved Excel ss with Scatter charts are modified

What are the steps to reproduce?

Run 32_Chart_read_write.php edited to select ONLY Scatter Charts, and to modify the data from the input template ss

32_Chart_read_writeScatterOnly.php.txt



### Which versions of PhpSpreadsheet and PHP are affected?
PHP version 7.4.29
phpoffice/phpspreadsheet version 1.22.0
@bridgeplayr
Copy link
Author

I have been trying to create Excel spreadsheets with data extracted from a MySQL db. I start with a template ss containing several Scatter Charts, then add the data. None of the saved charts are accepted by Excel (Microsoft 365 MSO Version 2203.)

As a result, I tried to emulate the sample code contained in 32_Chart_read_write.php. I modified that code slightly to

  1. limit the template xlsx Charts to Scatter Charts1-5. (See above code.)
  2. modify the chart data by adding a constant offset for each table entry
  3. to save the output file to a folder I could access instead of the unhelpful helper's choice of /tmp

My observations of the input vs output ss's are:

  • In all output charts, the x-axis changes from 0-14 with no offset, to 1-12 with offset.

  • The rich text font in the Chart Title is changed in all of the output charts.

  • input template: 32readwriteScatterChart1.xlsx - "No join and Markers"

  • output chart differences: points joined with lines; data point color changed from yellow to theme green

  • (line type changed from "No line" to "automatic");

  • input template: 32readwriteScatterChart2 - "Scatter - Join Bezier and Markers"

  • output chart differences; points joined with straight lines instead of Bezier curves.

  • Input template: 32readwriteScatterChart3 - "Scatter - Join Straight Lines and Markers"

  • output chart differences; no additional changes

  • input template: 32readwriteScatterChart4 - "Scatter - Join Bezier and No Markers"

  • output chart differences; straight lines instead of Bezier curves

  • input template: 32readwriteScatterChart5 - "Scatter - Join Straight Lines No Markers"

  • output chart differences; no additional changes

It seems that the "Chart type" selection is munged (Chart1 especially). There are many Chart Types, with sub-types, some of which affect the Plot Area and Theme, some which affect the way data points are connected (or not connected at all).

(Unfortunately, despite duplicating this "read-modify-write" scheme for creating my ss-with-scatter-charts, Excel still complains and removes my scatter charts. This bug report is NOT about that problem - that will be a stackoverflow submission. However, I think there may be a connection between the behavior I observed from the Sample 32_Chart_r-w and my problem)

@oleibman
Copy link
Collaborator

@bridgeplayr Not sure why you closed this. For now, I am reopening it.

@oleibman oleibman reopened this Apr 21, 2022
@bridgeplayr
Copy link
Author

bridgeplayr commented Apr 21, 2022 via email

@oleibman
Copy link
Collaborator

It appears to me that Reader/Xlsx/Chart has no support for the spPr tag, under which there is a noFill tag for Chart1, which is probably what handles the 'no join'. Likewise, there is markup under spPr for Chart2 which handles the Bezier curves. Even if the reader did support those, Writer/Xlsx/Chart generates nofill only for Stock Charts, and may not generate the Bezier tags at all. I'm guessing that there will also need to be changes to Chart/Chart and maybe its siblings to support this. So, this will not be a quick fix.

@bridgeplayr
Copy link
Author

Details about the Chart Titles --
input ss: Calibri-Bold-12pt-Black Kerning enabled for fonts 12 pt and above
output ss: Calibri-Regular-18pt Black. No Kerning enabled, Normal spacing.

@oleibman oleibman added the charts label May 1, 2022
oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue May 13, 2022
Chart issues have been pouring in recently. This is a partial response to issue PHPOffice#2762. It implements "no joins" for scatter charts, as well as having the reader and writer handle "point size", "line width", and "color" for markers. A new boolean property `scatterLines`, with setter and getter, is added to DataSeriesValues to handle joins (default is true which means scatter plot points *are* joined by lines). Some, but not yet all, default font properties for the chart title are handled (color and, surprisingly, font name present challenges).

With these changes, sample 32readwriteScatterChart1.xlsx now looks closer to its source. There are still some differences (x-axis changes), but I think this change is already large enough. I can work on the other problems later.

The code for reading charts has not yet been converted to be namespace aware. Having a tiny island of aware code in a sea of unaware makes no sense to me, so some of the new code is likewise unaware. I hope to be able to get to it eventually, but, among other considerations, it is difficult to generate suitable test cases.
oleibman added a commit that referenced this issue May 17, 2022
* Some Fixes for Scatter Charts

Chart issues have been pouring in recently. This is a partial response to issue #2762. It implements "no joins" for scatter charts, as well as having the reader and writer handle "point size", "line width", and "color" for markers. A new boolean property `scatterLines`, with setter and getter, is added to DataSeriesValues to handle joins (default is true which means scatter plot points *are* joined by lines). Some, but not yet all, default font properties for the chart title are handled (color and, surprisingly, font name present challenges).

With these changes, sample 32readwriteScatterChart1.xlsx now looks closer to its source. There are still some differences (x-axis changes), but I think this change is already large enough. I can work on the other problems later.

The code for reading charts has not yet been converted to be namespace aware. Having a tiny island of aware code in a sea of unaware makes no sense to me, so some of the new code is likewise unaware. I hope to be able to get to it eventually, but, among other considerations, it is difficult to generate suitable test cases.

* Add Formal Tests

Essentially the same as the corresponding Samples, but with formal assertions.

* Clean Up Some Code in Reader/Xlsx/Chart

Having added code to support default font attributes as well as element-specific font attributes for chart captions, there was duplicated code between the default and specific sections. I hope that this PR makes the code easier to follow.

* Add Support for Font Name and Color to XLSX Chart Titles

XML layout for these in new files differs from what program was expecting. Not sure if program expectations were wrong, or if this is a change to Excel since initial development.

* Minor Improvement

Handle theoretical case where Chart title has text but no font information.

* Support Bezier Curve and Scaling of X-Axis on Scatter Plot

For Bezier, need to specify `<c:smooth>` tag in addition to already supplied `<c:scatterStyle val="smoothMarker">`

For X-Axis, scatter needs to supply both X and y axis as `<c:valAx>` rather than `<c:catAx>` for X.
MarkBaker added a commit that referenced this issue Jul 9, 2022
Note that this will be the last 1.x branch release before the 2.x release. We will maintain both branches in parallel for a time; but users are requested to update to version 2.0 once that is fully available.

### Added

- Added `removeComment()` method for Worksheet [PR #2875](https://github.com/PHPOffice/PhpSpreadsheet/pull/2875/files)
- Add point size option for scatter charts [Issue #2298](#2298) [PR #2801](#2801)
- Basic support for Xlsx reading/writing Chart Sheets [PR #2830](#2830)

  Note that a ChartSheet is still only written as a normal Worksheet containing a single chart, not as an actual ChartSheet.

- Added Worksheet visibility in Ods Reader [PR #2851](#2851) and Gnumeric Reader [PR #2853](#2853)
- Added Worksheet visibility in Ods Writer [PR #2850](#2850)
- Allow Csv Reader to treat string as contents of file [Issue #1285](#1285) [PR #2792](#2792)
- Allow Csv Reader to store null string rather than leave cell empty [Issue #2840](#2840) [PR #2842](#2842)
- Provide new Worksheet methods to identify if a row or column is "empty", making allowance for different definitions of "empty":
  - Treat rows/columns containing no cell records as empty (default)
  - Treat cells containing a null value as empty
  - Treat cells containing an empty string as empty

### Changed

- Modify `rangeBoundaries()`, `rangeDimension()` and `getRangeBoundaries()` Coordinate methods to work with row/column ranges as well as with cell ranges and cells [PR #2926](#2926)
- Better enforcement of value modification to match specified datatype when using `setValueExplicit()`
- Relax validation of merge cells to allow merge for a single cell reference [Issue #2776](#2776)
- Memory and speed improvements, particularly for the Cell Collection, and the Writers.

  See [the Discussion section on github](#2821) for details of performance across versions
- Improved performance for removing rows/columns from a worksheet

### Deprecated

- Nothing

### Removed

- Nothing

### Fixed

- Xls Reader resolving absolute named ranges to relative ranges [Issue #2826](#2826) [PR #2827](#2827)
- Null value handling in the Excel Math/Trig PRODUCT() function [Issue #2833](#2833) [PR #2834](#2834)
- Invalid Print Area defined in Xlsx corrupts internal storage of print area [Issue #2848](#2848) [PR #2849](#2849)
- Time interval formatting [Issue #2768](#2768) [PR #2772](#2772)
- Copy from Xls(x) to Html/Pdf loses drawings [PR #2788](#2788)
- Html Reader converting cell containing 0 to null string [Issue #2810](#2810) [PR #2813](#2813)
- Many fixes for Charts, especially, but not limited to, Scatter, Bubble, and Surface charts. [Issue #2762](#2762) [Issue #2299](#2299) [Issue #2700](#2700) [Issue #2817](#2817) [Issue #2763](#2763) [Issue #2219](#2219) [Issue #2863](#2863) [PR #2828](#2828) [PR #2841](#2841) [PR #2846](#2846) [PR #2852](#2852) [PR #2856](#2856) [PR #2865](#2865) [PR #2872](#2872) [PR #2879](#2879) [PR #2898](#2898) [PR #2906](#2906) [PR #2922](#2922) [PR #2923](#2923)
- Adjust both coordinates for two-cell anchors when rows/columns are added/deleted. [Issue #2908](#2908) [PR #2909](#2909)
- Keep calculated string results below 32K. [PR #2921](#2921)
- Filter out illegal Unicode char values FFFE/FFFF. [Issue #2897](#2897) [PR #2910](#2910)
- Better handling of REF errors and propagation of all errors in Calculation engine. [PR #2902](#2902)
- Calculating Engine regexp for Column/Row references when there are multiple quoted worksheet references in the formula [Issue #2874](#2874) [PR #2899](#2899)
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