Skip to content
This repository has been archived by the owner on Jan 2, 2019. It is now read-only.

PHP Excel Radar and Scatter charts won't open in Excel 2007 #956

Closed
petehenshall opened this issue Jul 20, 2016 · 5 comments
Closed

PHP Excel Radar and Scatter charts won't open in Excel 2007 #956

petehenshall opened this issue Jul 20, 2016 · 5 comments

Comments

@petehenshall
Copy link

petehenshall commented Jul 20, 2016

Running the default origin/1.8 develop/1.8 example file 33-createdchart-radar.php from linux PHP 5.6, windows PHP 5.6 and macos PHP5.6 and PHP7 throws an error.
All these environments at least create an error in Excel when opening the file:

"Excel found unreadable content in'file.xlsx'. Do you want to recover the contents of this workbook?"
If you click Yes you get the result of another error:
"Repaired records: Drawing from /xl/drawings/drawing1.xml part (drawing shape).
When the xlsx file open ups you get the "Test Radar Chart" from 0 to 1.5 but with no data points plotted.

The file opens correctly on Open Office.

The log files for the repairs is as follows:

error087680_01.xml

Errors were detected in file 'C:\Users\Pete\Sites\File.xlsx'

Repaired Records: Drawing from /xl/drawings/drawing1.xml part (Drawing shape)

Any assistance appreciated. All the files you will need to reproduce this issue are in the origin/1.8 as long as you open on Excel 2007 you will see the problem. There are various reports on stackover flow to this problem but none present a solution.

Extra info: I tried useing jpgraph to create the radar chart but it errors with a:
"JPGraph Error: 25044 = Cannot use auto scaling since it is impossible to determine a valid min/max value of the y axis (only null values)."
unless I output the chart first into the worksheet in which case it will then run.

@petehenshall
Copy link
Author

petehenshall commented Jul 20, 2016

Similar to this issue: #645 but that reports that it is fixed but it isn't for Excel 2007.

@TheoBaart
Copy link

TheoBaart commented Jul 28, 2016

I was experiencing the same issues with my scatterplots. I think I found a solution to it:

In 33chartcreate-scatter.php building the dataseries is given as follows:

$series = new PHPExcel_Chart_DataSeries(
    PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART,   // plotType
    NULL,                                           // plotGrouping (Scatter charts don't have any grouping)
    range(0, count($dataSeriesValues)-1),           // plotOrder
    $dataSeriesLabels,                              // plotLabel
    $xAxisTickValues,                               // plotCategory
    $dataSeriesValues,                              // plotValues
    NULL,                                           // smooth line
    PHPExcel_Chart_DataSeries::STYLE_LINEMARKER     // plotStyle
);

However, if you look in the source code PHPExcel/Chart/DataSeries.php shows that the constructor for a PHPExcel_Chart_DataSeries has an extra element ($plotDirection) between $plotValues and $smootLine

public function __construct(
    $plotType = null, 
    $plotGrouping = null, 
    $plotOrder = array(), 
    $plotLabel = array(),
    $plotCategory = array(), 
    $plotValues = array(), 
    $plotDirection = null, 
    $smoothLine = null, 
    $plotStyle = null)
    {
   /* The constructor code */
}

So if you update your $series to look as follows (note the inserted plotDirection )it should work:

$series = new PHPExcel_Chart_DataSeries(
    PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART,   // plotType
    NULL,                                           // plotGrouping (Scatter charts don't have any grouping)
    range(0, count($dataSeriesValues)-1),           // plotOrder
    $dataSeriesLabels,                              // plotLabel
    $xAxisTickValues,                               // plotCategory
    $dataSeriesValues,                              // plotValues
    NULL,                                           // plotDirection
    NULL,                                           // smooth line
    PHPExcel_Chart_DataSeries::STYLE_LINEMARKER     // plotStyle
);

I quickly looked at 33chartcreate-radar.php and it is also missing the $plotDirection field, so I believe the same fix should work for radar plots as well.

@petehenshall
Copy link
Author

Great stuff @TheoBaart can't believe I missed that! I burnt about 8 hours looking in the end.. frustratingly it was opening in OpenOffice so I was looking way deeper than just the example in the source code file being fundamentally wrong!
I can't thank you enough sir.
Kind regards!

@petehenshall
Copy link
Author

p.s. to anyone else reading this obviously change:

$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART, // plotType

to

$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_TYPE_RADARCHART, // plotType

If you want a RADAR chart.

then include the extra NULL in the constructor before
PHPExcel_Chart_DataSeries::STYLE_LINEMARKER // plotStyle

as thoebaart pointed out.

Then it should all work.

@MarkBaker
Copy link
Member

Thanks for identifying that problem; I've fixed it in the develop branch on github

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants