How to setup jpgraphs and wxgraphs

Glad you like it Martin.

Stuart

You wouldn’t happen to know if it’s possible to use the different language files for the jpgraphs when my website is set to a specific language?

If you check my main page, I’ve added the temperature over last 7 days graphs in the dashboard. I was wondering if I can
get it to display the text in the correct language depending on the choice for the template…

Best Regards,
Martin

If you have the latest package there is a graphlang.php file which you can edit to change the language.

Stuart

And that could be made selectable the same way the template pages work eg http://www.berdalweather.net/index.php?lang=en

Currently I only have one other language file other than English and that’s Danish, so at present I’ve not bothered to change the code to make it user selectable you simply rename the correct language file to graphsconf.php. Its quite easy to change by making a small change to the config file but as I’d only received one langauge file I’d not done it.

Stuart

Yes, that was my point, how to get the jscript to choose between the different language files for the wxgraphic dependant on the main language selected in the Carterlake template.

I’m not so good at coding stuff from scratch, so I was hoping someone could help me out. :slight_smile:

Best Regards,
Martin

WEell it would need more than a simple code change in the config file as these graphs are for everyone not just those running the Carterlake Templates. Also currently there are only English and Danish available anyway. For now simply edit the graphlang file and change to your language. When I get time I’ll try to add the required code to the config file and make it work with and without the templates.

Stuart

Thanks Stuart!

I’m just using the default English version for now, although I’ve created a Norwegian file as well.

Best Regards,
Martin

Hi all,

I was wondering if any of you code gurus could help me with something I’d like to do with this temp graph.
I’d like to make it fill the below zero temperatures with blue, and the above zero temperatures with red.
Also, change the plot line from a fixed color to the same, ie. red if above zero and blue if below zero.

Here’s the graph:

And here’s my current code (don’t pay so much attention to the colors I’ve chosen etc it’s just for testing):

<?php
// Graphs Package V2.1 16th March 2008
if (!file_exists("graphsconf.php")) include("error_msg.php");
include ("graphsconf.php");
if (!file_exists($jploc."jpgraph.php")) {
  $string = "Unable to find JPGraph files";
  create_image1($string,$jploc);
  exit;
}
include ($jploc."jpgraph.php");
include ($jploc."jpgraph_line.php");

$clientrawextra = get_raw("${hostloc}clientrawextra.txt");

//temp=========================================================================
$y=array($clientrawextra['21'],$clientrawextra['22'],$clientrawextra['23'],$clientrawextra['24'],
$clientrawextra['25'],$clientrawextra['26'],$clientrawextra['27'],$clientrawextra['28'],$clientrawextra['29'],
$clientrawextra['30'],$clientrawextra['31'],$clientrawextra['32'],$clientrawextra['33'],$clientrawextra['34'],
$clientrawextra['35'],$clientrawextra['36'],$clientrawextra['37'],$clientrawextra['38'],$clientrawextra['39'],
$clientrawextra['40'],$clientrawextra['566'],$clientrawextra['567'],$clientrawextra['568'],$clientrawextra['569']);
$datay = $y;




if ($temp_conv == 1.8) {
	array_walk($datay, "CtoF");
	}

//Check for negative values in array and do a SetAuotMin(0) if none
array_walk($datay, "NegVal");
$negvalue1 = $negvalue;

// Check for positive values in array
array_walk($datay, "PosVal");
$posvalue1 = $posvalue;

$negvalue = 0;
$posvalue = 0;

if (($negvalue1 == 1) or ($negvalue3 == 1)) $negvalue = 1;
if (($posvalue1 == 1) or ($posvalue3 == 1)) $posvalue = 1;
if (($negvalue1 == 0) and ($negvalue3 == 0)) $negvalue = 0;
if (($posvalue1 == 0) and ($posvalue3 == 0)) $posvalue = 0;

if ($negvalue == 0) {
  if ($temp_conv == 1) $automin = '$graph->yaxis->scale->SetAutoMin(0);';
  if ($temp_conv == 1.8) $automin = '$graph->yaxis->scale->SetAutoMin(32);';
  $grace = '$graph->yaxis->scale->SetGrace(5);';
}
if (($negvalue == 1) and ($posvalue == 0)) {
  if ($temp_conv == 1) $automin = '$graph->yaxis->scale->SetAutoMax(0);';
  if ($temp_conv == 1.8) $automin = '$graph->yaxis->scale->SetAutoMax(32);';
  $grace = '$graph->yaxis->scale->SetGrace(0,5);';
}
if (($negvalue == 1) and ($posvalue == 1)) {
  $automin = '';
  $grace = '$graph->yaxis->scale->SetGrace(5,5);';
}

//create timearray for the x-axis
$x=array($clientrawextra['459'],$clientrawextra['460'],$clientrawextra['461'],$clientrawextra['462'],
$clientrawextra['463'],$clientrawextra['464'],$clientrawextra['465'],$clientrawextra['466'],$clientrawextra['467'],
$clientrawextra['468'],$clientrawextra['469'],$clientrawextra['470'],$clientrawextra['471'],$clientrawextra['472'],
$clientrawextra['473'],$clientrawextra['474'],$clientrawextra['475'],$clientrawextra['476'],$clientrawextra['477'],
$clientrawextra['478'],$clientrawextra['578'],$clientrawextra['579'],$clientrawextra['580'],$clientrawextra['581']);
$datax = $x;

// Create the graph and specify the scale for both Y-axis
$graph = new Graph($xsize,$ysize,"auto",30);    
$graph->SetScale("textlin");

$graph->SetShadow();
$graph->SetMarginColor("$margincolour");

// Adjust the margin
$graph->SetMargin($lm,$rm,$tm,$bm);

// Create the two linear plot
$lplot1=new LinePlot($datay);    // Temp






// Add the plot to the graph
$graph->Add($lplot1);


//titles
//$graph->title->Set("$txt_temp - Last 24 hrs ($temp_unit)");
//$graph->title->Align("center","top");
//$graph->title->SetFont(FF_ARIAL,FS_BOLD,10);
//$graph->title->SetColor("$textcolour");

//x-axis
//$graph->xaxis->title->SetColor("$xtextcolour");
//$graph->xaxis->title->Set("$txt_24h");
//$graph->xaxis->title->SetFont(FF_ARIAL,FS_BOLD,8);
$graph->xaxis->SetFont(FF_ARIAL,FS_BOLD,8);
$graph->xaxis->SetTitlemargin(25);
$graph->xaxis->SetLabelMargin(10);
$graph->xaxis->SetTickLabels($datax);
$graph->xaxis->SetLabelAngle($label_angle);
$graph->xaxis->SetTextLabelInterval($label_interval);
$graph->xaxis->SetPos("min"); 
$graph->xaxis->HideTicks(true,true); 
$graph->xaxis->SetColor("$xtextcolour"); 
$graph->xgrid->Show(true);

//y-axis
$graph->yaxis->SetFont(FF_ARIAL,FS_BOLD,8);
$graph->yaxis->SetColor("$ytextcolour");
$graph->yaxis->SetLabelFormat("%0.0f");
$graph->yaxis->HideTicks(false,false);
eval($automin);
eval($grace);

//y2-axis
//$graph->y2axis->SetFont(FF_ARIAL,FS_BOLD,8);
//$graph->y2axis->SetColor("$y2textcolour");
//$graph->yaxis->SetLabelFormat("$temp_format");
//$graph->y2axis->HideTicks(true,true); 
//$graph->y2axis->scale->SetAutoMin(0);

// Set the colors for the plots

if (($negvalue1 == 0) and ($posvalue1 == 1)) $lplot1->SetColor("$temp_col1");
if (($negvalue1 == 1) and ($posvalue1 == 0)) $lplot1->SetColor("$temp_col2");
if (($negvalue1 == 1) and ($posvalue1 == 1)) $lplot1->SetColor("$temp_col3");

if (($negvalue1 == 1) and ($posvalue1 == 0)) $lplot1->SetFillColor("#[email protected]");
if (($negvalue1 == 1) and ($posvalue1 == 1)) $lplot1->SetFillColor("#[email protected]");
$lplot1->SetWeight(1);




// Setup a background gradient image
$graph->SetBackgroundGradient('white','navy:0.5',GRAD_HOR,BGRAD_PLOT);

// Set the legends for the plots
//$graph->legend->SetFont(FF_ARIAL,FS_NORMAL,7);
//$lplot1->SetLegend("$txt_temp1");

// Adjust the legend position
//$graph->legend->SetLayout(LEGEND_HOR);
//$graph->legend->Pos(0.02,0.01,'right','top');

// Display the graph
$graph->Stroke();

?>

Best Regards,
Martin

Since we have now got more solar data in the clientrawhour.txt I have created a new graph called solar_1hr.php which is the solar values for the last whole hour. You just need to install the attached file and rename it to a .php file. I have not yet added this to the package, will do this later. You do need a a fairly recent version of WD for this to work.

Stuart


solar_1hr.txt (2.53 KB)

Hi Stuart

I have installed the solar last whole hour graph and its working perfect - both in Danish and English.

Best regards,

Henrik

Hi all,

I tried to create a language selectable image. So i placed the current line into the graphsconf.php

$lang = 'en'; // default language to be used (lowercase, must correspond to available

// overrides from Settings.php if available
global $SITE;
if (isset($SITE[‘lang’])) {$lang = $SITE[‘lang’]; }
// end of overrides from Settings.php

The image changed successfully when i change the first line $line = ‘en’
But it never took the language from the language selector used in the saratoga templates.

Why is this global site setting not coming trough in the graphsconf.php
Can somebody explain this ?
Is this because its an image and not an php inclusion ??

Thanks

Maurice

The way the language works in these graphs is that it always includes the graphlang.php and you have to rename the relevant language file to graphlang.php and overwrite the default file. If you want this to work you need to re-write the language logic so that it dynamically includes the correct language file. I never wrote it to do this originally mainly because I only ever got sent one language file so I just did not think there was a need.

Stuart

Hi Stuart,

I did change the language file from graphlang.php to graphland-en.php and graphlang-nl.php for dutch.
And when i change the language behind $lang = ‘en’; to $lang = ‘nl’ it does change the language.

But i can’t get the language value from the setting.php to overwrite the file language.

Maurice

Ah OK, well where in the execution of the script is the settings.php script called? As you rightly say these are images and called directly from the browser when it hits the image tag so its not inline code with the call to create the HTML data. You need to add a call to settings.php somewhere probably in graphconf file, but be careful since this is not my code there is no guarantee that there will be no conflict between variables and other things in the settings.php, my code was not designed to co-exist in execution with Ken’s code, it may work but just be aware…

Stuart

:smiley: :smiley: Yes yes it’s working !!! :smiley: :smiley:

Take a look http://www.weerstationloosduinen.nl/wxabout.php?lang=en

the image language is changing when another language is selected.
I Changed the default graphlang.php to graphlang-en.php and also created a dutch version graphlang-nl.php


graphsconf.txt (9.25 KB)

Just a quick question concerning the 1 hour graphs. I noticed it was the last full hour graphs. Is there a way that it could be current instead of the last full hour. I hope I make sense. By the way nice graphs Stuart, must have taken a while to get those all.

Chuck

Chuck

I don’t think the data is there to support a rolling 60 mins.

"Weather-Display clientrawhour.txt Description

This contains an array of 60 unit each representing the last 60 minutes of each value. It is updated at 59 minutes after the hour by WD."

This is what I got from the parser. It looks like to me it is the last hour and not the last whole hour. Somebody correct me if I am wrong. :wink:

[quote]181 Temp Last 60 for Min 01 C 18.6

It would be if it was updated each minute, but if it’s only updated hourly at 59 mins past the hour then it is effectively the last clock hour.