One thing I've been struggling with in pChart is keeping the Y axis within the boundaries of the compass directions. In my case I am attempting to plot wind direction for a weather station, however the resulting charts always come out with a scale of 0-400. This prevents me from adding meaningful customizations such as defining horizontal bars at 0, 90, 180, and 270 degrees.
Some sample code to generate results...
<?php
include("pchart/class/pData.class.php");
include("pchart/class/pDraw.class.php");
include("pchart/class/pImage.class.php");
$points = array(0, 10, 90, 270, 345, 355);
$scale = array(
'Mode' => SCALE_MODE_MANUAL,
'ManualScale' => array(0=>array("Min"=>0,"Max"=>360)),
);
$data = new pData();
$data->addPoints($points, "dir");
$picture = new pImage(256, 128, $data, TRUE);
$picture->setFontProperties(array("FontName" => "pchart/fonts/GeosansLight.ttf","FontSize" =>10));
$picture->setGraphArea(40,10,216,108);
$picture->drawScale($scale);
$picture->drawPlotChart(array("PlotSize"=>1,"PlotBorder"=>TRUE,"BorderSize"=>1));
$picture->Render("wind.png");
echo "<img src='wind.png'>";
And the resulting chart...
Wind direction chart results
As you can see, the Y axis does not honor the requested ManualScale settings despite the data points being well within the boundaries. I have tried use a Max of 359 and 360 (with 360 being the more correct choice since decimal values may be entered). I have also tried specifying scale MinDivHeight (divided by 5 to get the four compass directions) and/or Factors (testing with multiples of 90), but values are always overwritten in favor of a chart that spans 0-400. On the other hand, using a scale of 0-100 for percentage data works exactly as expected.
Am I missing something, or is this just a limitation of pChart that makes it impossible to perform this simple task?
It turns out I was really close to an answer and didn't realize it. The "Factors" attribute is barely mentioned in the pChart wiki with no information on how to use it, but I had previously run across a discussion of it where the answer was to provide the value in the amount you wanted to split your axis by. That answer was only partially correct -- you must supply an array that also includes the number of times you want to split the axis.
So to answer my own question, I needed to add another line to the $scale array:
'Factors' => array(4,90)
With that line in place, setting Max to either 359 or 360 both resulted in a chart with a scale of 0-360, including horizontal breaks automatically created at 0, 90, 180, 270, and 360. Once I applied this line to my existing code it generated a wind direction plot exactly as desired.
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.
Is there any way to set a LinePlot->SetFillColor to go upwards instead of going down in JPGraph - PHP?
$p6 = new LinePlot($arrayLimSpecI);
$graph->Add($p6);
$p6->SetColor("#0B610B");
$p6->SetWeight(3);
$p6->SetStyle("solid");
//FillColor Fills the plotline from point 0 to point X
$p6->SetFillColor('red#0.65');
What I've tried:
$band = new PlotBand(HORIZONTAL,BAND_SOLID,$valueS,"max",'red');
$band->ShowFrame(false);
$graph->AddBand($band);
But this band doesn't seem to adjust to the dynamic marks that the graphic has got. If I set valueS to show on Y-Mark 10 it will show instead on the mark point 40.
EDIT: Another library that is currently supported or is capable or doing this is welcomed.
i need some help, google makes me sad
I got polygon http://geojson.io/#id=gist:anonymous/069b8a955897723ca256&map=4/58.75/48.03
And it covering a lot.
And i got geoPHP library https://github.com/phayes/geoPHP
Which got methods contains, covers, coveredBy...
And everything is normal, except that point like 74.224074, 96.428248 is always false for methods contains,coveredBy,covers, etc for this polygon. But it must be true.
Please, tell me why. I got a headache.
OR
Tell me please, how check that the lat lng is inside polygon. I tested about 3 libraries in perl and php, making my own code, etc... But the right results i got only from google containsLocation in javascript. But i have to use it on server side, not in browser. If there any chance to use containsLocation in nodejs it would be very nice.
Thank you
A little code for geoPHP:
$a='JSON FROM LINK';
$b=geoPHP::load("POINT(74.224074 96.428248)","wkt");
$a=geoPHP::load($a, 'json');
$result=$a->contains($b);
var_dump($result);
And it will be false
EDIT:
I think i got it.
GeoJson making coordinates in wrong way, longtitude, latitude. But it must be latitude, longtitude.
Will try and then write here if it works
ANSWER:
Use this www.birdtheme.org/useful/v3tool.html to make polygon on maps. It making it in right way(latitude,longtitude)
Working code for geoPHP:
include_once('geoPHP.inc');
$addr=file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($_GET['address']).'&sensor=false');
foreach($addr->{results} as $addr1)
{
if(array_key_exists("geometry",$addr1)){
$lat=$addr1->{geometry}->{location}->{lat};
$lng=$addr1->{geometry}->{location}->{lng};
break;
}
}
$point1 = geoPHP::load("POINT($lat $lng)","wkt");
$ya200=geoPHP::load("POLYGON((41.51 12.3, 38.27 28.83, 32.55 41.84, 27.6 55.55, 29.54 71.37, 33.43 83.32, 36.6 94.92, 36.6 99.49, 35.17 111.45, 32.55 124.8, 35.17 130.78, 39.64 142.73, 43.58 152.58, 45.83 166.29, 56.17 163.83, 63.07 159.26, 68.66 154.69, 72.18 148.71, 75.93 140.63, 78.49 129.02, 80.3 114.26, 80.98 100.2, 81.2 87.54, 80.87 73.83, 79.62 59.41, 76.27 40.43, 71.07 28.13, 67.2 23.2, 63.55 20.04, 59.01 17.23, 54.16 15.12, 48.46 13.36,41.51 12.3))","wkt");
var_dump($ya200->contains($point1));
I am the maintainer of the geoPHP library (https://geophp.net). You have your latitude and longitude mixed up. WKT specifies that x comes first, then y, and then (optionally) z. This makes sense, as we usually do things in XYZ order.
It's conventional in mathematics for the horizontal axis to be X, and the vertical axis to be Y. If we think of a globe overlaid on a piece of graphing paper with X and Y axes specified, we can see that longitude is the horizontal axis, which corresponds to X, and the latitude is the vertical axis, which corresponds to Y. Therefore reading it as "longitude, latitude" makes perfect sense.
Regrettably, this sensical approach is backwards from the way mariners and other cartographers have described coordinates on the globe it throughout history. Historically it has often been described as "latitude, longitude".
This clash of history vs mathematical-convention is why you see different conventions in different systems. In Google Maps API its "latitude, longitude", while in OpenLayers it's "longitude, latitude".
In this particular case, you are using WKT, which is specified in "longitude, latitude" order.
WKT format expects POINT(lon, lat), with lon being first. You mixed up the order. Corrected:
geoPHP::load("POINT($lon $lat)","wkt");
I have answered almost the same question but don't know how to make a repost of it, so I just repeat it here (sorry)
If you use this PHP library (https://github.com/xopbatgh/sb-polygon-pointer), it may do all you need
(but first you need to convert GEOjson coordinates to lat/lng)
Plan to do:
Insert the coordinates of your polygon into array
Ask the library is the any point with lat/lng inside this polygon
$polygonBox = [
[55.761515, 37.600375],
[55.759428, 37.651156],
[55.737112, 37.649566],
[55.737649, 37.597301],
];
$sbPolygonEngine = new sbPolygonEngine($polygonBox);
$isCrosses = $sbPolygonEngine->isCrossesWith(55.746768, 37.625605);
// $isCrosses is boolean
After hours of struggle, I could not get the contains method to work with geoPHP. It turns out, as pointed out from this SO response that the geos library needs to be installed manually (no composer), which I could not get working after sifting through documentation on archive.org.
As an alternative, I found the mjaschen/phpgeo to be simple to use to do polygon contains point calculations. Simply load in your lat lons to objects and call the contains method as outlined in the documentation:
$polygon = new Polygon();
$polygon->addPoint(new Coordinate(12.3, 41.51));
$polygon->addPoint(new Coordinate(28.83, 38.27));
$polygon->addPoint(new Coordinate(41.84, 32.55));
$point = new Coordinate(74.224074, 96.428248)
var_dump($polygon->contains($point))
All advanced methods in geoPHP requires that GEOS is installed. If You are not able to install it but still want to use intersects test for point and polygon, then I have forked geoPHP and added Polygon->pointInPolygon and MultiPolygon->pointInPolygon methods for that purpose. Take a look:
https://github.com/sookoll/geoPHP
$point = \geoPHP::load('POINT (x y)','wkt');
$polygon = \geoPHP::load('POLYGON ((x y...))','wkt');
$point_is_in_polygon = $polygon->pointInPolygon($point);
I have this php code for creating a line chart, i have put the whole chart tag inside a PHP variable
$XMLNPK = "<chart formatNumberScale='0' showValues='1' decimals='0' shadowAlpha='40' bgColor='FFFFFF,99CCFF' labelDisplay='ROTATE' rotateValues='1' slantLabels='1' formatNumberScale='0' decimalPrecision='0' showvalues='1' animation='1' numdivlines='5' numVdivlines='0' caption='Plant Population Vs Yield - FCV' adjustDiv='0' yAxisMinValue='1900' yAxisMaxValue='2100' numDivLines='5'>";
What I wanted to do is to add this php variables which contains the max and min value of a field into the yAxisMinValue and yAxisMaxValue
<?php
$maxfcv = max($yieldfcv);
$minfcv = min($yieldfcv);
?>
I tried this following code but it doesn't show the value:
...numVdivlines='0' caption='Plant Population Vs Yield - FCV' adjustDiv='0' yAxisMinValue='".$minfcv."' yAxisMaxValue='".$maxfcv."' numDivLines='5'>
Can anyone help me on this. Thank you in advance. :-)
Make sure any of the chart's value is not beyond (greater than the max or lower than the min) the limits you are setting. If true, the chart does not crop the overflowing sections, rather it auto-calculates new min and max to make the line properly visible int he canvas.