Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.5 (build 3282) - 23 February 2024

Cumulus MX V4 beta test release 4.0.0 (build 4017) - 17 March 2024

Legacy Cumulus 1 release v1.9.4 (build 1099) - 28 November 2014 (a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

Server Generated Graphs for MX

From build 3044 the development baton passed to Mark Crossley. Mark has been responsible for all the Builds since. He has made the code available on GitHub. It is Mark's hope that others will join in this development, but at the very least he welcomes your ideas for future developments (see Cumulus MX Development suggestions).

Moderator: mcrossley

Post Reply
User avatar
mcrossley
Posts: 12641
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Server Generated Graphs for MX

Post 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/
Last edited by mcrossley on Sat 30 Jan 2016 11:44 am, edited 12 times in total.
water01
Posts: 3201
Joined: Sat 13 Aug 2011 9:33 am
Weather Station: Ecowitt HP2551
Operating System: Windows 10 64bit
Location: Burnham-on-Sea
Contact:

Re: Server Generated Graphs for MX

Post 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?
David
Image
User avatar
mcrossley
Posts: 12641
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Server Generated Graphs for MX

Post 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.
water01
Posts: 3201
Joined: Sat 13 Aug 2011 9:33 am
Weather Station: Ecowitt HP2551
Operating System: Windows 10 64bit
Location: Burnham-on-Sea
Contact:

Re: Server Generated Graphs for MX

Post 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?
David
Image
User avatar
mcrossley
Posts: 12641
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Server Generated Graphs for MX

Post 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
Last edited by mcrossley on Tue 27 Jan 2015 2:59 pm, edited 1 time in total.
n9mfk
Posts: 845
Joined: Sun 10 May 2009 8:52 pm
Weather Station: davis vp2 Serial datalogger
Operating System: Windows 7 64-bit
Location: Springfield, IL

Re: Server Generated Graphs for MX

Post by n9mfk »

Hi Mark
working great

could jpgraph draw
windrose.png
why did you pick jpgraph over highcharts?
Beau
You do not have the required permissions to view the files attached to this post.
User avatar
mcrossley
Posts: 12641
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Server Generated Graphs for MX

Post 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 ;)
water01
Posts: 3201
Joined: Sat 13 Aug 2011 9:33 am
Weather Station: Ecowitt HP2551
Operating System: Windows 10 64bit
Location: Burnham-on-Sea
Contact:

Re: Server Generated Graphs for MX

Post 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!!
David
Image
User avatar
mcrossley
Posts: 12641
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Server Generated Graphs for MX

Post 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();
User avatar
mcrossley
Posts: 12641
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Server Generated Graphs for MX

Post by mcrossley »

I have updated the zip to support PHP versions < 5.4
n9mfk
Posts: 845
Joined: Sun 10 May 2009 8:52 pm
Weather Station: davis vp2 Serial datalogger
Operating System: Windows 7 64-bit
Location: Springfield, IL

Re: Server Generated Graphs for MX

Post by n9mfk »

Hi Mark,
I was looking at the jpgraph config file it looks like cache is off by defualt
Beau
User avatar
mcrossley
Posts: 12641
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Server Generated Graphs for MX

Post by mcrossley »

I think you may be right, you have to enable it in jpg-config-inc.php and set the folder to use.
n9mfk
Posts: 845
Joined: Sun 10 May 2009 8:52 pm
Weather Station: davis vp2 Serial datalogger
Operating System: Windows 7 64-bit
Location: Springfield, IL

Re: Server Generated Graphs for MX

Post 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
Last edited by n9mfk on Tue 27 Jan 2015 5:26 pm, edited 2 times in total.
User avatar
mcrossley
Posts: 12641
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Server Generated Graphs for MX

Post 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)?
water01
Posts: 3201
Joined: Sat 13 Aug 2011 9:33 am
Weather Station: Ecowitt HP2551
Operating System: Windows 10 64bit
Location: Burnham-on-Sea
Contact:

Re: Server Generated Graphs for MX

Post 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']);  
David
Image
Post Reply