Takes an array or data, an array of options and produces a graph image of the data array. Has options for colors, size of image, transparancy, titles (x, y, graph). Could use some improvements though.
By : ahzzmandius
function GraphRows($rows, $opts) { # options # # box_x_size: width of values area # box_y_size: height of the values area # x_size: total width of the graph # y_size: total height of the graph # x_val: array element of record to assign as x_value # y_val: array element to assign as y_value # x_label: label for the Bottom of the graph # y_label: label for the left side # font: font number to use from system # font_file: file to use as the font # show_x_val: true == show X value of each bar with the y_label # show_y_val: true == show Y value labels # title: string for top of graph # bar_color: color array to use for bars # box_color: color to use for the box edging and value box. # label_color: color for the labels # val_color: color to to use for the values # title_color: color to use for the title. # bg_color: color for the background. # bg_trans: make the background transparant. # img_format: can be "png", "gif", or "jpg".
#the boxed area with be 2 from the top and right, 30 from the left, and 12 from the bottom. # the border will be 1px wide. $max_x = 0; $max_y = 0; $longest_x = 0; $longest_y = 0; $x_mod = 1.3; $y_mod = 1.3;
# find the longest x and y value str lengths for the label margin size. foreach($rows as $idx => $row) { $y_val = $row; $x_val = $idx; if(is_array($row)) { foreach($row as $idx => $val) { $y_val = $val; break; } if($opts["y_val"]) { if(array_key_exists($opts["y_val"], $row)) { $y_val = $row[$opts["y_val"]]; } }
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.