Description:
The Graph class enables SteelBlue to line, bar, stacked bar, pie graphs, and tables using the Draw class and the QuickImage application. The QuickImage application is a pair of programs developed by the Turner Consulting Group: a Java applet for client-side drawing, and a CGI program for server-side drawing. The choice for client or server-side drawing is determined by the value of the boolean member Draw::use_java.Data is represented as an array (similar to a spreadsheet) in which the rows are the data sets and the columns are the individual data elements. The type of graph is determined by the member Graph::graph_type.
There are two ways of adding data to the graph object. The first is to access the data array directly though the method Graph::setData($row,$col,$value), which allows you to randomly populate the data array. The second technique is to append to the existing rows of data through Graph::appendToRow($row,$value), which appends appends the given value to the specified data set. The numbering for rows and columns start at 0. Values which are not set, or are set to the empty string ("") are considered undefined and may not be depicted depending upon the type of graph.
Members:
commands - The command string sent to QuickImage data_format - The format used to display the data graph_type - The type of graph displayed height - The height of the graph pie_dataset - Dataset (row) used for a pie chart pie_slice - Element (column) separated from the rest of the pie subtitle - The subtitle of the graph title - The title of the graph use_java - Flag whether to use QuickImage java class or CGI program use_labels - Flag whether to display pop-up labels use_legend - Flag whether to display a legend width - The width of the graph x_title - The x axis title of the graph y_title - The y axis title of the graph
Methods:
appendToRow($row,$value) - Appends the data value to the given data set (row) drawHorizLine($color,$y,$label) - Draws a labeled horizontal line on line and bar graphs getData($row,$col) - Gets the data value for the data set (row) and element (column) getDataColor($item) - Gets the color for the data item in hexadecimal as "RRGGBB" Graph($w,$h,$type) - Constructor setting the width, height, and type Graph() - Constructor outputGraph() - Writes IMG tag, APPLET tag, or TABLE to display the graph setColLabel($col,$label) - Sets the label for the data element (column) setData($row,$col,$value) - Sets the data value for the data set (row) and element (column) setDataColor($item,$rgb) - Sets the color for the data item in hexadecimal as "RRGGBB" setDataShadeColor($item) - Gets the 3D shade color for the data item in hexadecimal as "RRGGBB" setDataShadeColor($item,$rgb) - Sets the 3D shade color for the data item in hexadecimal as "RRGGBB" setRowLabel($row,$label) - Sets the label for the data set (row)
Example:
// Collect rows of random data in a graph object
$g = new Graph();
for($i=0;$i<3;$i=$i+1){
for($j=0;$j<10;$j=$j+1){
$g.setColLabel($j,"Col ".$j);
$g.appendToRow($i,rand(100));
}
}
// Create titles and labels
$g.title = "Random Numbers";
$g.xtitle = "Sample";
$g.ytitle = "Value";
$g.setRowLabel(0,"First");
$g.setRowLabel(1,"Second");
// Output a 3D-line graph using Java
$g.width = 500; $g.height = 200;
$g.graph_type = "3DLINE";
$g.use_java = 1;
$g.outputGraph();
// Output a Pie chart using a server side GIF
// using the same data
$g.graph_type = "3DPIE";
$g.width = 300; $g.height = 200;
$g.pie_dataset = 1; // Use second series
$g.pie_slice = 0; // Separate the first slice of the pie
$g.use_java = 0;
$g.outputGraph();
// Output the data in a simple table
$g.graph_type = "TABLE";
$g.outputGraph();| Member name: commands | Class Graph |
Description:
The command string sent to QuickImage. This is not intended to be directly modified, but instead is created through calling the drawing methods.
| Member name: data_format | Class Graph |
Description:
The format used to display the data. If set to "Money" then the values are displayed with a beginning "$" and two decimal points of precision. If set to "Percent" then the values are multiplied by 100 and displayed with a trailing "%". Otherwise the values are displayed labeled as plain integer or real numbers depending upon their values.
| Member name: graph_type | Class Graph |
Description:
The type of graph displayed. Options are "Line", "3DLine", "Bar", "3DBar", "Pie", "3DPie", "StackedBar", "3DStackedBar", and "Table". It defaults to "3DLine".
| Member name: height | Class Graph |
Description:
The height of the graph (defaults to 200).
| Member name: pie_dataset | Class Graph |
Description:
The dataset (row number) used for a pie chart. It defaults to "0".
| Member name: pie_slice | Class Graph |
Description:
The element (column number) separated from the rest of the pie. It defaults to "0". If set to the empty string (""), then no slice is separated from the pie.
| Member name: subtitle | Class Graph |
Description:
The title of the graph
| Member name: title | Class Graph |
Description:
The title of the graph
| Member name: use_java | Class Graph |
Description:
Flag whether to use QuickImage Java class or CGI program (defaults to CGI program). If use_java is set to a non-zero integer, then the QuickImage Java class (client-side drawing) is used. If use_java is zero (the default), then the QuickImage CGI program (server-side drawing) is used.
| Member name: use_labels | Class Graph |
Description:
Flag whether to display pop-up labels for bar graphs, or print values next to the legend for pie charts. If use_labels is one (the default), then pop-up labels are displayed. If use_labels is zero, labels are not displayed.
| Member name: use_legend | Class Graph |
Description:
Flag whether to display a legend. If use_legend is one (the default), then a legend is displayed. If use_legend is zero, a legend is not displayed.
| Member name: width | Class Graph |
Description:
The width of the graph (defaults to 300).
| Member name: x_title | Class Graph |
Description:
The x axis title of the graph
| Member name: y_title | Class Graph |
Description:
The y axis title of the graph
| Member name: appendToRow($row,$value) | Class Graph |
Description:
Appends the data value to the given data set ($row). The value is placed after the last assigned value for the given row.
Usage:
$graph.appendToRow($row,$value)
| $row | - | Data set (row) |
| $value | - | Data value to append to the data set |
| Member name: drawHorizLine($color,$y,$label) | Class Graph |
Description:
Draws a labeled horizontal line on line and bar graphs. The line appears in the specified color at the $y coordinate (in the data's coordinate space), and labeled in black text with the string given in $label.
Usage:
$graph.drawHorizLine($color,$y,$label)
| $color | - | Color for the line |
| $y | - | Y location (in the data coordinates) for the line |
| $label | - | Text label for the line |
| Member name: getData($row,$col) | Class Graph |
Description:
Gets the data value for the given data set ($row) and element ($col). The numbering for rows and columns begin at "0".
Usage:
$value = $graph.getData($row,$col)
| $row | - | Data set (row) |
| $col | - | Data element (column) |
| $value | - | Returned data value |
| Member name: getDataColor($item) | Class Graph |
Description:
Gets the color for the data row or column (depending on the graph type) specified as a hexadecimal "RRGGBB" number (red, green, and blue). For line graphs, $item represents the data set (row) number. For bar, stacked bar, or pie charts, $item represents the data element (column) number. By default, the colors are determined by an algorithm cycling through primary colors, secondary colors, and then progressively darker versions of each.
Usage:
$rgb = $graph.getDataColor($item)
| $item | - | Data item number |
| $rgb | - | Color specified in hexadecimal as "RRGGBB" |
| Member name: Graph($w,$h,$type) | Class Graph |
Description:
Creates a new graph object, setting the width to $w, the height to $h, and the graph type to $type.
Usage:
$graph = new Graph($w,$h,$type);
| $graph | - | Resulting drawing object |
| Member name: Graph() | Class Graph |
Description:
Creates a new graph object.
Usage:
$graph = new Graph();
| $graph | - | Resulting graph object |
| Member name: outputGraph() | Class Graph |
Description:
Writes the IMG tag, APPLET tag, or TABLE to display the drawing. If the graph type is "Table", then an HTML table is displayed. Otherwise, if the method Draw::use_java is non-zero, am APPLET tag is written to call the QuickImage Java applet. If the method Draw::use_java is zero, then the IMG tag is written to call the QuickImage CGI applet (in which case the Quick Image commands are written to a temporary file).
Usage:
$graph.outputGraph()
| Member name: setColLabel($col,$label) | Class Graph |
Description:
Sets the label for a data element (column). This appears in the legend for bar, stacked bar, and pie charts.
Usage:
$graph.setColLabel($col,$label)
| $col | - | Data element (column) number |
| $label | - | Label string |
| Member name: setData($row,$col,$value) | Class Graph |
Description:
Sets the data value for the given data set ($row) and element ($col). The numbering for rows and columns begin at "0".
Usage:
$graph.setData($row,$col,$value)
| $row | - | Data set (row) |
| $col | - | Data element (column) |
| $value | - | Data value |
| Member name: setDataColor($item,$rgb) | Class Graph |
Description:
Sets the color for the data row or column (depending on the graph type) specified as a hexadecimal "RRGGBB" number (red, green, and blue). For line graphs, $item represents the data set (row) number. For bar, stacked bar, or pie charts, $item represents the data element (column) number.
Usage:
$graph.setDataColor($item,$rgb)
| $item | - | Data item number |
| $rgb | - | Color specified in hexadecimal as "RRGGBB" |
| Member name: setDataShadeColor($item) | Class Graph |
Description:
Gets the 3D shade color for the data row or column (depending on the graph type) specified as a hexadecimal "RRGGBB" number (red, green, and blue). For line graphs, $item represents the data set (row) number. For bar, stacked bar, or pie charts, $item represents the data element (column) number. By default, the colors are determined by an algorithm cycling through primary colors, secondary colors, and then progressively darker versions of each.
Usage:
$rgb = $graph.getDataShadeColor($item)
| $item | - | Data item number |
| $rgb | - | Color specified in hexadecimal as "RRGGBB" |
| Member name: setDataShadeColor($item,$rgb) | Class Graph |
Description:
Sets the 3D Shade color for the data row or column (depending on the graph type) specified as a hexadecimal "RRGGBB" number (red, green, and blue). For line graphs, $item represents the data set (row) number. For bar, stacked bar, or pie charts, $item represents the data element (column) number.
Usage:
$graph.setDataShadeColor($item,$rgb)
| $item | - | Data item number |
| $rgb | - | Color specified in hexadecimal as "RRGGBB" |
| Member name: setRowLabel($row,$label) | Class Graph |
Description:
Sets the lebel for a data set (row).
Usage:
$graph.setRowLabel($row,$label)
| $row | - | Data set (row) number |
| $label | - | Label string |