Page 1 of 14

Server Generated Graphs for MX

Posted: Mon 26 Jan 2015 9:07 pm
by mcrossley
The attached PHP scripts use the JSON files MX creates and the JPGraph package to create static recent trend graph image files - useful if you want to include them in your SteelSeries gauges popups, or anywhere else on your site. You can see them working on my gauges page.

The scripts use the JPGraphs file caching system, the images are generated on demand, but pulled from the cache if the previous version is within the time (default is 10 minutes). I didn't like the overhead of a cron job endlessly redrawing them if nobody needs them.

Most of the settings you need to alter are in the graphSettings.php script.

I have included a .htaccess file so that if you have an Apache server, you can get the scripts via the image names used in C1 (plus some extra variations).

Please note, I have found that JPGraphs ver 3.5.0b1 has a bug in the caching system. The fix for the bug is to edit "gd_image.inc.php", and add a 'return true' at line 2266 in the function GetAndStream()...

Code: Select all

function GetAndStream($aImage,$aCacheFileName) {
        if( $this->Isvalid($aCacheFileName) ) {
            $this->StreamImgFile($aImage,$aCacheFileName);
            return true;
        }
        else {
            return false;
        }
    }
I don't want to spend a lot of time supporting these scripts, so please take them and modify as you see fit.

Note: The get the Wind Rose plot working correctly, I had to add the arial.ttf and verdana.ttf font files to the JPGraphs font folder.

PS. If you want some much nicer looking jpgraph based graphs for displaying on a page, then Kevin at TNET Weather has a template for download. They will need adapting to use the MX json files though.

I have moved the source for these graphs onto GitHub, feel free to download them from there, and branch/modify to your hearts content. I'll merge back any updates that you think are of value to others - like adding a readme and how-to guide!

https://github.com/mcrossley/Cumulus-MX-Gauge-Graphs/

Re: Server Generated Graphs for MX

Posted: Tue 27 Jan 2015 1:28 pm
by water01
Ok I will be the thicky.
the images are generated on demand
On demand from what i.e. what does the call to generate the images using the PHP?

Re: Server Generated Graphs for MX

Posted: Tue 27 Jan 2015 1:34 pm
by mcrossley
The end user. When they display a page that uses one of the graphs, it will be drawn then - or pulled from cache.

Re: Server Generated Graphs for MX

Posted: Tue 27 Jan 2015 2:26 pm
by water01
But presumably you have to change the imgPathURL in gauges.js to /jgraph/cache/ ?

And excuse the ignorance but does the .htaccess settings cause the dynamic generation of the appropriate .png file?

Re: Server Generated Graphs for MX

Posted: Tue 27 Jan 2015 2:34 pm
by mcrossley
No, you point the gauges.js to where the scripts are.

For instance mine are in my /images folder, so to get the temperature graph I can access the php directly...

http:// weather.wilmslowastro.com/images/graphTempOut.php

Or using the .htaccess...

http:// weather.wilmslowastro.com/images/temp.png
Image

Re: Server Generated Graphs for MX

Posted: Tue 27 Jan 2015 2:48 pm
by n9mfk
Hi Mark
working great

could jpgraph draw
windrose.png
why did you pick jpgraph over highcharts?
Beau

Re: Server Generated Graphs for MX

Posted: Tue 27 Jan 2015 2:58 pm
by mcrossley
n9mfk wrote:Hi Mark
working great

could jpgraph draw
windrose.png
Looks like it: http://jpgraph.net/features/gallery.php#rader1
n9mfk wrote:why did you pick jpgraph over highcharts?
Err, HighCharts are drawn client side ;)

Re: Server Generated Graphs for MX

Posted: Tue 27 Jan 2015 3:00 pm
by water01
OK Mark I must be being extremely thick. What links the ?.png file to the ?.php file, the settings in .htaccess?

And I do not see any images in your post just image not found holders which is the same as if I try
http://weather.wilmslowastro.com/images ... empOut.php or
http://weather.wilmslowastro.com/images/temp.png

and also if call graphTempOut.php directly in a URL I get

Parse error: syntax error, unexpected '[' in /home/dmjsyste/public_html/weather/images/graphSettings.php on line 14

Code: Select all

$GRAPH  = []; 
I cannot see how logically this fits together and I am sitting here kicking myself because I must be missing something!!

Re: Server Generated Graphs for MX

Posted: Tue 27 Jan 2015 3:09 pm
by mcrossley
Ah, you are running an older version of PHP that does not support the [] array syntax - I always use that because of my JavaScript brain!

So you will need to change
$GRAPH = [];
and
$retVal = [];

to
$GRAPH = array();
and
$retVal = array();

Re: Server Generated Graphs for MX

Posted: Tue 27 Jan 2015 3:36 pm
by mcrossley
I have updated the zip to support PHP versions < 5.4

Re: Server Generated Graphs for MX

Posted: Tue 27 Jan 2015 3:42 pm
by n9mfk
Hi Mark,
I was looking at the jpgraph config file it looks like cache is off by defualt
Beau

Re: Server Generated Graphs for MX

Posted: Tue 27 Jan 2015 4:00 pm
by mcrossley
I think you may be right, you have to enable it in jpg-config-inc.php and set the folder to use.

Re: Server Generated Graphs for MX

Posted: Tue 27 Jan 2015 4:32 pm
by n9mfk
Mark,
after some test

Code: Select all

define('CACHE_DIR','./jpgraph/cache/');

Code: Select all

 define('USE_CACHE',true); 
must be set beau

Re: Server Generated Graphs for MX

Posted: Tue 27 Jan 2015 4:55 pm
by mcrossley
It obviously does work :) Steve tested it for me and implemented the graphs on his web site too.

What error are you getting? Have you checked the error log on your server (if you have access to it)?

Re: Server Generated Graphs for MX

Posted: Tue 27 Jan 2015 5:00 pm
by water01
Think there maybe a problem with the code at Line 22 in graphWdir.php for those of us on < 5.4.

Code: Select all

$graph->yaxis->SetMajTickPositions([0, 45, 90, 135, 180, 225, 270, 315, 360], ['Calm', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'N']);