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

An option to create scatter chart with data points not connected with lines #2297

Closed
GajowyJ opened this issue Sep 15, 2021 · 2 comments · Fixed by #2828
Closed

An option to create scatter chart with data points not connected with lines #2297

GajowyJ opened this issue Sep 15, 2021 · 2 comments · Fixed by #2828
Labels

Comments

@GajowyJ
Copy link

GajowyJ commented Sep 15, 2021

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?

An user can define scatter chart with data points not connected with lines.

What is the current behavior?

Data points are always connected with lines on a scatter chart.

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

// just create any scatter chart 

Which versions of PhpSpreadsheet and PHP are affected?

PHP 8.0.10
PhpSpreadsheet 1.18.0

@GajowyJ
Copy link
Author

GajowyJ commented Sep 15, 2021

Proposed solution:

  1. In Chart\DataSeriesvalues.php add following code:
class DataSeriesValues
{
	// ...
	private $isLine = TRUE;
	public function isLine(bool $new=NULL) : bool
	{
		if( is_null($new) )
			return $this->isLine;
		$tmp=$this->isLine;
		$this->isLine = $new;
		return $tmp;
	}
	// ...
}
  1. In Writer\Xlsx\Chart.php add following code:
private function writePlotGroup( //...
{
	// ...
	//    Formatting for the points
	if ( // ...
	{
		// ...
	}
	if( !$plotSeriesValues->isLine() && $groupType == DataSeries::TYPE_SCATTERCHART )
	{
		$objWriter->startElement('c:spPr');
		$objWriter->startElement('a:ln');
		$objWriter->writeAttribute('w', 0);
		$objWriter->startElement('a:noFill');
		$objWriter->endElement();	// a:noFill
		$objWriter->endElement();	// a:ln
		$objWriter->endElement();	// c:spPr
	}
	// ...
}

@bridgeplayr
Copy link

I can verify that these changes produce the desired results. Thank you, @GajowyJ

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.

3 participants