Using PHPSpreadsheet to make a two line scatter chart. I put in the x and Y values from the spreadsheet cells. PHPSpreadsheet generates the chart with a ugly X-axis. Y data ie about 17 degrees C to about 45 degrees C. The Y axis is 0 to 50in 5 degree increments, perfect. But, the X data is 0 to 34 minutes in 2 minute increments. The X axis is 0 to 35 minutes in one minute increments. I am attaching a picture of both.
This is the X axis ticks and the data set:
$xAxisTickValues = [
new
DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$1:$C$18', null, 18),
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$F$1:$F$18', null, 18)
];
dataSeriesValues = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$1:$D$18' ,null , 18),
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$G$1:$G$18' ,null , 18)
];
No errors are involved. The expected or desired results would be an X axis of 0 to 40 in 5 degree increments.
The good chart x axis was achieved by right clicking the bad chart selecting xy scatter chart and clicking OK. Excel made the good axis automatically?
Would someone please guide me to get the proper axis using PHPSpreadsheet.
I do know the answer to my question, almost. Both x and y axis are supposed to be controlled by the following code:
$xaxis = new Axis();
$xaxis->setAxisOptionsProperties('low', 0, 'autoZero', null, 'in', 'out', 0, 40, 5, 0);
$title = new Title('Calorimetric Calibration');
$yAxisLabel = new Title(html_entity_decode('Temp (°C)',ENT_QUOTES,'UTF-8'));
$xAxisLabel = new Title('Time (Min)');
// Create the chart
$chart = new Chart(
'chart1', // name
$title, // title
$legend, // legend
$plotArea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
$xAxisLabel, // xAxisLabel
$yAxisLabel, // yAxisLabel
$yaxis,
$xaxis,
null,
null
);
I can vary all aspects of the y axis. But I can not do anything with the x axis max and min. It appears they are controlled by the following:
$xAxisTickValues = [
new
DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1:$C$18', null, 18),
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$F$1:$F$18', null, 18)
];
If I remove the tick marks control, it them appears the x axis is controlled by the number of data points. So, that is where the almost comes in my answer. How can I get the setAxisOptionsProperties to take over and allow me the set the max and mins as I want to?