JPGraph error, A plot has an illegal scale - php

I'm trying to make a graph with JPGragph, but I keep getting an error saying:
JpGraph Error A plot has an illegal scale. This could for example be that you are trying to use text auto scaling to draw a line plot with only one point or that the plot area is too small. It could also be that no input data value is numeric (perhaps only '-' or 'x')
$ydata = round($ydata[0]); // An attempt to convert float to int
$ydata = (int)$ydata; // That didn't bring any solution(thought it couldn't handle float)
$pt = new LinePlot($ydata); // Here is where the error is thrown
$bar2->Add($pt);
$pt->SetColor("blue");
$pt->SetWeight(10);
I've tried to replace $ydata with an integer, but that only throws an fatal error.
Without the round and type cast, this is the var_dump of $ydata:
array(1) { [0]=> float(8.1102970953135) }

I just had the same problem using PHP 7.2 when the plot only contains one data point.
The reason seems to be that JPGraph tries to put the single data point on the left and the right edge of the plot at the same time.
Using $plot->SetCenter(); fixed the issue for me and it looks better for BoxPlots.

Working with PHP 7? I got the same error and found this:
http://jpgraph.net/doc/faq.php#F4-13
They say your PHP Installation is "faulty".
What helped me was to add a second value to the data array - only one value did just not work.

Related

PHPSpreadsheet generates an error "Wrong number of arguments for INDEX() function: 5 given, between 1 and 4 expected"

I tried to enter the following code in my excel formula bar directly
=INDEX($E$4:$E$132,AGGREGATE(15,6,ROW($1:$30) / ($J$4:$J$132=M4), COUNTIF($M$4:M4, M4))) and works perfectly fine (the left column on the pic below).
But if I'm using my web application to generate an excel report file (PHP, using CodeIgniter and Laravel). It displays an error "'Wrong number of arguments for INDEX() function: 5 given, between 1 and 4 expected'"
Here's my sample code snippet:
$code = "=INDEX(\$E\$4:\$E\$$occurance, AGGREGATE(15,6,ROW(\$1:\$$occurance) / (\$J\$4:\$J\$$occurance=M$top_cell), COUNTIF(\$M\$4:M$top_cell, M$top_cell)))";
$ews2->setCellValue("L$top_cell", $code);
I also have tried to use the setValueExplicit method but causes the excel file to NOT precalculate the code, it reads the code as a string
$ews2->setCellValueExplicit("L$top_cell", $code, DataType::TYPE_STRING);
NOTE TYPE_STRING is provided because if TYPE_FORMULA is also used, the same output mentioned at the top occurs
Here's what it looks like using the setCellValueExplicit
May I know the right solution or quick fix for this? Thank you very much in advance!
I have found out that the PHPSpreadsheet library for PHP is yet to allow the usage of the AGGREGATE() and complicated formulas/functions, so I had found another way around
By using this excel code
=INDEX(E$2:E$38,IF(M4=M3,MATCH(L3,E$2:E$38,0),0)+MATCH(M4,OFFSET(J$2,IF(M4=M3,MATCH(L3,E$2:E$38,0),0),0,COUNT(J$2:J$38)-IF(M4=M3,MATCH(L3,E$2:E$38,0),0),1),0))
I was able to traverse through my entire range and make sure that no duplicate publication names would appear
This is in relation with the my other question -> Excel - Getting the 2nd or nth matched string from your corresponding data

PHPExcel: problem while writing cell data type issue

I have PHP code to export the data to excel. Used PHPExcel library for the same.
PHPExcel library Version 1.7.6
We encountered a problem while writing the following value ==PD==[HW]RECEIVING CRC ERRORS
When I open the Excel manually and set the cell data type as TEXT it is accepting this value.
But while trying to generate the excel using PHPExcel library, getting an error as below exception 'Exception' with message 'L14 -> Formula Error: Unexpected operator '=''
I tried to solve this issue by setting the data type of the cell as STRING, but no luck... Tried below ways to set the cell data type...
#first try
$activeSheet->setCellValueExplicit($symptomColumn.$rowCount, $val, PHPExcel_Cell_DataType::TYPE_STRING);
#second try
$activeSheet->getCell($symptomColumn.$rowCount)->setValueExplicit($val, PHPExcel_Cell_DataType::TYPE_STRING);
#third try
$activeSheet->getCell($symptomColumn.$rowCount)->setDataType(PHPExcel_Cell_DataType::TYPE_STRING);
#fourth try
$activeSheet->getStyle($symptomColumn.$rowCount)
->getNumberFormat()
->setFormatCode(
PHPExcel_Style_NumberFormat::FORMAT_GENERAL
);
#fifth try
$activeSheet->getStyle($symptomColumn.$rowCount)
->getNumberFormat()
->setFormatCode(
PHPExcel_Style_NumberFormat::FORMAT_TEXT
);
Can anyone please help me to resolve the issue while writing the text "==PD==[HW]RECEIVING CRC ERRORS" to the cell while creating an excel using PHPExcel library?
Thanks in Advance...
If PHPExcel encounters a cell where the first character of content is an =, then it considers that cell to contain an Excel formula, and will try to evaluate it as such. If it isn't actually a formula, then it will throw an exception like this.
There is no simple solution in PHPExcel, other than to suggest that you add a leading space (or other character) before the =. PHPExcel is no longer a supported library, and this bug will not be fixed (especially not in the older version that you are running).
The latest master branch of the successor library PHPSpreadsheet does contain a fix for this, allowing you to set the style of the cell to quoted text. This will identify that this is not a formula to the calculation engine, and is similar to what you are recommended to do in MS Excel itself.
$workSheet->setCellValue('A2', "==PD==[HW]RECEIVING CRC ERRORS");
$workSheet->getCell('A2')->getStyle()->setQuotePrefix(true);

PHPExcel Multiple worksheet formula returning PHPExcel_Calculation_Exception

Goodevening,
I'm using the PHPExcel Library to populate an existing Excel sheet with some data, and show the result of the calculated value on a webpage.
I've got a couple of formulas that look like this:
=IF(OR($B$7=$A$17;$B$8=$A$17;$B$9=$A$17);"";B9)
=IF(B12<=B14;IF(B12=A17;A17;VLOOKUP(CEILING(B12;1);'Motor selection'!$1:$1048576;2;FALSE));A17)
I get the following error when I try to get the calculated value of 'B9' for example:
Fatal error: Uncaught exception 'PHPExcel_Calculation_Exception' with message 'Pump selection!D7 -> Pump selection!B9 -> Formula Error: An unexpected error occured' in includes/PHPExcel/Classes/PHPExcel/Cell.php:291
I'm using the following PHP code, which is pretty standard.
$objType = PHPExcel_IOFactory::identify($file);
$objReader = PHPExcel_IOFactory::createReader($objType);
$objPHPExcel = $objReader->load($file);
// Populate values
$objPHPExcel->getActiveSheet()->setCellValue('B4', 100)
->setCellValue('B5', 75);
// Motor
$motor = $objPHPExcel->getActiveSheet()->getCell('B9')->getFormattedValue();
As I am not an Excel expert (a client sent me this) I have no clue what is going wrong or how to fix this. All I know is that the formulae in the sheet itself are working fine when I open it in Excel.
Would love to know if someone can assist me on this. I can share the complete Excel file if that's necessary.
Thanks in advance,
Kevin
Edit: I've read that the issues might have something to do with the dollar signs in the formula, and I've already tried escaping them with \$ but that doesn't seem to make a difference.
Edit2: The file can be found here. Idea is that B4 and B5 of the first sheet get populated with form data, and the result will be in D7:H7.

PChart - Y Axis does not start from 0

I generate stacked bar chart using PChart, but Y Axis does not start from 0.
Is there manual parameter that I should set? Here the chart
$graph->drawScale(array("Mode" => SCALE_MODE_START0));
This works for standard bar charts, I assume it would work for stacked. Give it a try.
There are actually a couple of ways to solve this issue. According to the documentation you should be able to use:
$graph->drawScale(array("Mode"=> SCALE_MODE_ADDALL_START0));
however, when I was generating stacked charts, it kept adding an additional mark at 110%, to solve this I decided to use:
$scaleProperties = array(0=>("Min"=>0, "Max"=>100));
$graph->drawScale(array("Mode" => SCALE_MODE_MANUAL, "ManualScale"=>$scaleProperties));
You would simply change the "Max" value to whatever your top end is, this forces the scale to stay between 0 and the maximum value.

how to draw a rectangle whose the coordinates are stored in a mysql database?

I store my rectangles in the database like so:
1) transfer, by ajax, of the rectangle coordinate to a PHP script;
rectangle.getBounds()
2) store the rectangle in mysql (with a PHP script)
Now I would like to draw the rectangles stored in mysql database:
1) read the coordinates;
$rectangle = $row['rectangle']
$rectangle has the following structure ((x1,y1),(x2,y2))
2) transfer, by ajax, to the javascript script.
echo json_encode($rectangle);
in javascript "$rectangle" becomes "coordinate"
3) finally draw the rectangle
var r = new google.maps.Rectangle({bounds: coordinate, ...});
r.setMap(map);
Unfortunately a parse error message is displayed instead of rectangles.
Any ideas of my errors ?
Note: hope that this simplified code is understandable. If not I can add code.
the bounds property of RectangleOptions is a google.maps.LatLngBounds object. You need to convert the value returned from your database into one.
Parse the coordinate values out of the string and use them to create a google.maps.LatLngBounds object.

Categories