Link to home
Start Free TrialLog in
Avatar of altariamx2003
altariamx2003Flag for Mexico

asked on

how to create a scatter graph with straight lines

Hi im working with phpexcel and im trying to create a excel file with a scatther graph with straight lines
this is the code that im using:
$xAxisTickValues = array(
	new PHPExcel_Chart_DataSeriesValues('Number', '\'Phase Envelope No. 1\'!$B$11:$B$'.$linea, NULL,  4),	//	Q1 to Q4
	new PHPExcel_Chart_DataSeriesValues('Number', '\'Phase Envelope No. 1\'!$D$11:$D$'.$linea, NULL, 4),	//	Q1 to Q4
);

$dataSeriesValues = array(
	new PHPExcel_Chart_DataSeriesValues('Number', '\'Phase Envelope No. 1\'!$C$11:$C$'.$linea, NULL, 4),
	new PHPExcel_Chart_DataSeriesValues('Number', '\'Phase Envelope No. 1\'!$E$11:$E$'.$linea, NULL, 4),
);

//	Build the dataseries
$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
	NULL,								// plotLabel
	$xAxisTickValues,								// plotCategory
	$dataSeriesValues,								// plotValues
	NULL,											// smooth line
	PHPExcel_Chart_DataSeries::STYLE_SMOOTHMARKER		// plotStyle
);
//	Set the series in the plot area
$plotarea = new PHPExcel_Chart_PlotArea(NULL, array($series));
//	Set the chart legend
$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_TOPRIGHT, NULL, false);
$title = new PHPExcel_Chart_Title('Test Scatter Chart');
$yAxisLabel = new PHPExcel_Chart_Title('Value ($k)');
//	Create the chart
$chart = new PHPExcel_Chart(
	'chart1',		// name
	NULL,			// title
	NULL,		// legend
	$plotarea,		// plotArea
	true,			// plotVisibleOnly
	0,				// displayBlanksAs
	NULL,			// xAxisLabel
	NULL		// yAxisLabel
);
//	Set the position where the chart should appear in the worksheet
$chart->setTopLeftPosition('G10');
$chart->setBottomRightPosition('Q39');
//	Add the chart to the worksheet
$objPHPExcel->getActiveSheet()->addChart($chart);

Open in new window


And this is the graph that i get:
User generated image
but as you see the labels in the x-axis are bad, i want to produce something like this:User generated image
What im missing?? do i need to add something else in my code?
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

SSCCE, please.  Ideally we should be able to copy your code and test data, and get the same output when we install your script on our servers.

If we can get that, then we can experiment with it, and maybe find a workable solution.
Avatar of altariamx2003

ASKER

hi ray

i made an example, the data is the same just i change the way how i load in the excel file-test3.php
 

and also this the excel file that the phpscript produce-filename.xlsx
Thanks - I think I can work with that.  Where can I download a copy of the PHPExcel scripts?
there you go ray

-php.zip
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
im gonna check the link

thx ray