Note that there are some explanatory texts on larger screens.

plurals
  1. POPERL RRDTTOL: graph subroutine with conditional legend
    text
    copied!<p>Stupid thing I can't manage...</p> <p>in Perl, with RRDTool (rrds module), I create a common subroutine to create the graphs for the different time period (1 day, 1 week,...). I want to use some sub argument to also display optional legend.</p> <p>With the following code, that does not generate any graph....</p> <pre><code>#!/usr/bin/perl use strict; use OWNet; use RRDs; use warnings; use diagnostics; my $rrd = '/var/rrd/electricite.rrd'; my $img = '/mnt/ds211/web/'; &amp;CreateGraph("conso","Consommation electrique 1 heure","1h",1); sub CreateGraph # inputs: $_[0]: sensor_rrd_name # $_[1]: chart title # $_[2]: interval period (1h,24h,7d,1m,1y,10y) # $_[3]: Puissance instantanee (1/0) { my $temp_graph; $temp_graph ="\"$img$_[0]-$_[2].png\","; $temp_graph .="\"--start=end-$_[2]\","; $temp_graph .="\"--end=now\","; $temp_graph .="\"--width=600\","; $temp_graph .="\"--height=200\","; $temp_graph .="\"--slope-mode\","; $temp_graph .="\"--title=$_[1]\","; $temp_graph .="\"--vertical-label=Watt\","; $temp_graph .="\"--lower-limit=0\","; $temp_graph .="\"--alt-autoscale-max\","; $temp_graph .="\"DEF:energy=$rrd:$_[0]:AVERAGE\","; $temp_graph .="\"CDEF:Watt=energy,3600,*\","; $temp_graph .="\"LINE2:Watt#0000FF:\","; $temp_graph .="\"AREA:Watt#00FF00:\","; $temp_graph .="\"VDEF:WattHour=energy,TOTAL\","; if ($_[3]==1) { $temp_graph .="\"GPRINT:Watt:LAST: Puissance instantanee\\: %6.2lf%sW\","; } $temp_graph .="\"GPRINT:WattHour: Consommation totale\\: %6.2lf%sWh\\n\","; $temp_graph .="\"GPRINT:Watt:MIN: Puissance min\\: %6.2lf%sW\","; $temp_graph .="\"GPRINT:Watt:AVERAGE: Puissance moyenne\\: %6.2lf%sW\","; $temp_graph .="\"GPRINT:Watt:MAX: Puissance max\\: %6.2lf%sW\""; RRDs::graph ("$temp_graph"); if ($ERROR = RRDs::error) { print "$0: failed to generate graph $_[0] data into rrd: $ERROR\n"; } } </code></pre> <p>thank you</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload