php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #60125 Incorrect OOP example for rrd graphs
Submitted: 2011-10-24 23:58 UTC Modified: 2012-01-07 18:26 UTC
From: jeff at freethoughtdesign dot com Assigned: frozenfire (profile)
Status: No Feedback Package: rrd (PECL)
PHP Version: Irrelevant OS: OS X
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jeff at freethoughtdesign dot com
New email:
PHP Version: OS:

 

 [2011-10-24 23:58 UTC] jeff at freethoughtdesign dot com
Description:
------------
The OOP example (http://www.php.net/manual/en/rrd.examples-oop.php) suggests that options to the RRDGraph be set as key:value pairs, and that works for some options, but it did not work for --color options until I used the syntax found on the procedural example page here: http://www.php.net/manual/en/rrd.examples-procedural.php

The key:value syntax makes a bit more sense to me, but either way it seems like it should be consistent.

The following only partially worked - the color settings had no effect:

<?php
    $img->setOptions(
      array(
        "--start" => time() - 3600,
        "--end" => time(),
        "--vertical-label" => "Watts",
        "--slope-mode",
        "--title" => "Power Usage",
        "--width" => "600",
        "--height" => "300",
        "--y-grid" => "100:5",
        "--units-exponent" => "0",
        "--full-size-mode",
        "--color" => "BACK#FAF8CC",
        "--color" => "CANVAS#6D7B8D",
        "--color" => "MGRID#00ff00",
        "--color" => "GRID#E8E8E8",
        "--color" => "FONT#153E7E",
        "--color" => "AXIS#00ff00",
        "--color" => "ARROW#00ff00",
        "--color" => "SHADEA#000000",
        "--color" => "SHADEB#000000",
        "DEF:Watt=$rrd_file:watts:AVERAGE",
        "CDEF:Low=Watt,0,1000,LIMIT",
        "CDEF:Mid=Watt,1000,2000,LIMIT",
        "CDEF:High=Watt,2000,3500,LIMIT",
        "CDEF:VHigh=Watt,3500,15000,LIMIT",
        "AREA:Low#00ff00:0-1000",
        "AREA:Mid#ffbf00:1000-2000",
        "AREA:High#FF0000:2000-3500",
        "AREA:VHigh#ffffff:> 3500\c",
        "COMMENT: \l",
        "GPRINT:Watt:LAST:Current\: %4.1lf Watts",
        "GPRINT:Watt:AVERAGE:Average\: %4.1lf Watts"
      )
    );
?>

In this version, based on the syntax in the procedural example, the graph colors worked correctly:

<?php
    $img->setOptions(
      array(
        "--start", time() - 3600,
        "--end", time(),
        "--vertical-label", "Watts",
        "--slope-mode",
        "--title", "Power Usage",
        "--width", "600",
        "--height", "300",
        "--y-grid", "100:5",
        "--units-exponent", "0",
        "--full-size-mode",
        "--color", "BACK#FAF8CC",
        "--color", "CANVAS#6D7B8D",
        "--color", "MGRID#00ff00",
        "--color", "GRID#E8E8E8",
        "--color", "FONT#153E7E",
        "--color", "AXIS#00ff00",
        "--color", "ARROW#00ff00",
        "--color", "SHADEA#000000",
        "--color", "SHADEB#000000",
        "DEF:Watt=$rrd_file:watts:AVERAGE",
        "CDEF:Low=Watt,0,1000,LIMIT",
        "CDEF:Mid=Watt,1000,2000,LIMIT",
        "CDEF:High=Watt,2000,3500,LIMIT",
        "CDEF:VHigh=Watt,3500,15000,LIMIT",
        "AREA:Low#00ff00:0-1000",
        "AREA:Mid#ffbf00:1000-2000",
        "AREA:High#FF0000:2000-3500",
        "AREA:VHigh#ffffff:> 3500\c",
        "COMMENT: \l",
        "GPRINT:Watt:LAST:Current\: %4.1lf Watts",
        "GPRINT:Watt:AVERAGE:Average\: %4.1lf Watts"
      )
    );
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-04 01:28 UTC] frozenfire@php.net
-Status: Open +Status: Feedback
 [2011-12-04 01:28 UTC] frozenfire@php.net
Could you please try changing your OOP version so that settings like "--slope-
mode" have a value, instead of having the option as the value.

For instance, use "--slope-mode" => true and "--full-size-mode" => true.

The reason I ask this is that the code for setOption in the rrd extension source 
uses a particular method to figure out which style you're using, which may screw 
up when you switch back and forth.
 [2011-12-04 01:28 UTC] frozenfire@php.net
-Assigned To: +Assigned To: frozenfire
 [2012-01-07 18:26 UTC] frozenfire@php.net
-Status: Feedback +Status: No Feedback
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 11:01:28 2024 UTC