If you use Cumulus, please donate Image

Please read this post before posting

Latest Cumulus release v1.9.4 (build 1099) - Nov 28 2014
Latest Cumulus MX release - v3.0.0 build 3043 Jan 20 2017. See this post for download

Server Generated Graphs for MX

Discussion of version 3 of Cumulus, which runs on Windows, Linux, and OS X. All Cumulus MX queries in here, please.
User avatar
mcrossley
Posts: 4805
Joined: Thu Jan 07, 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Jessie Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Server Generated Graphs for MX

Postby mcrossley » Mon Jan 26, 2015 9:07 pm

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 Jan 30, 2016 11:44 am, edited 12 times in total.

water01
Posts: 1368
Joined: Sat Aug 13, 2011 9:33 am
Weather Station: WH1081
Operating System: Windows 7 64bit HP SP1
Location: Gurney Slade,Somerset, UK
Contact:

Re: Server Generated Graphs for MX

Postby water01 » Tue Jan 27, 2015 1:28 pm

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?

User avatar
mcrossley
Posts: 4805
Joined: Thu Jan 07, 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Jessie Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Server Generated Graphs for MX

Postby mcrossley » Tue Jan 27, 2015 1:34 pm

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: 1368
Joined: Sat Aug 13, 2011 9:33 am
Weather Station: WH1081
Operating System: Windows 7 64bit HP SP1
Location: Gurney Slade,Somerset, UK
Contact:

Re: Server Generated Graphs for MX

Postby water01 » Tue Jan 27, 2015 2:26 pm

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?

User avatar
mcrossley
Posts: 4805
Joined: Thu Jan 07, 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Jessie Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Server Generated Graphs for MX

Postby mcrossley » Tue Jan 27, 2015 2:34 pm

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 Jan 27, 2015 2:59 pm, edited 1 time in total.

n9mfk
Posts: 845
Joined: Sun May 10, 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

Postby n9mfk » Tue Jan 27, 2015 2:48 pm

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: 4805
Joined: Thu Jan 07, 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Jessie Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Server Generated Graphs for MX

Postby mcrossley » Tue Jan 27, 2015 2:58 pm

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: 1368
Joined: Sat Aug 13, 2011 9:33 am
Weather Station: WH1081
Operating System: Windows 7 64bit HP SP1
Location: Gurney Slade,Somerset, UK
Contact:

Re: Server Generated Graphs for MX

Postby water01 » Tue Jan 27, 2015 3:00 pm

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!!

User avatar
mcrossley
Posts: 4805
Joined: Thu Jan 07, 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Jessie Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Server Generated Graphs for MX

Postby mcrossley » Tue Jan 27, 2015 3:09 pm

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: 4805
Joined: Thu Jan 07, 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Jessie Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Server Generated Graphs for MX

Postby mcrossley » Tue Jan 27, 2015 3:36 pm

I have updated the zip to support PHP versions < 5.4

n9mfk
Posts: 845
Joined: Sun May 10, 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

Postby n9mfk » Tue Jan 27, 2015 3:42 pm

Hi Mark,
I was looking at the jpgraph config file it looks like cache is off by defualt
Beau

User avatar
mcrossley
Posts: 4805
Joined: Thu Jan 07, 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Jessie Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Server Generated Graphs for MX

Postby mcrossley » Tue Jan 27, 2015 4:00 pm

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 May 10, 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

Postby n9mfk » Tue Jan 27, 2015 4:32 pm

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 Jan 27, 2015 5:26 pm, edited 2 times in total.

User avatar
mcrossley
Posts: 4805
Joined: Thu Jan 07, 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Jessie Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Server Generated Graphs for MX

Postby mcrossley » Tue Jan 27, 2015 4:55 pm

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: 1368
Joined: Sat Aug 13, 2011 9:33 am
Weather Station: WH1081
Operating System: Windows 7 64bit HP SP1
Location: Gurney Slade,Somerset, UK
Contact:

Re: Server Generated Graphs for MX

Postby water01 » Tue Jan 27, 2015 5:00 pm

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']); 


Return to “Cumulus MX”

Who is online

Users browsing this forum: net_boy and 2 guests