/** * Create the plotarea, implicitely creates 2 normal axis */ function Image_Graph_Plotarea_Radar() { parent::Image_Graph_Element(); $this->_padding = 10; $this->_axisX =& Image_Graph::factory('Image_Graph_Axis_Radar'); $this->_axisX->_setParent($this); $this->_axisY =& Image_Graph::factory('Image_Graph_Axis', IMAGE_GRAPH_AXIS_Y); $this->_axisY->_setParent($this); $this->_axisY->_setMinimum(0); }
/** * Create the plotarea, implicitely creates 2 normal axis */ function __construct() { parent::__construct(); $this->_padding = array('left' => 10, 'top' => 10, 'right' => 10, 'bottom' => 10); $this->_axisX =& Image_Graph::factory('Image_Graph_Axis_Radar'); $this->_axisX->_setParent($this); $this->_axisY =& Image_Graph::factory('Image_Graph_Axis', IMAGE_GRAPH_AXIS_Y); $this->_axisY->_setParent($this); $this->_axisY->_setMinimum(0); }
/** Return the actual Image data * Classes must override this. * @param $child_html The child method's return value * @return A html fragment */ public function showImageData() { require_once "Image/Graph.php"; $db = AbstractDb::getObject(); $Graph =& Image_Graph::factory("Image_Graph", array(600, 200)); $Plotarea =& $Graph->add(Image_Graph::factory("Image_Graph_Plotarea")); $Dataset =& Image_Graph::factory("Image_Graph_Dataset_Trivial"); $Bar =& Image_Graph::factory("Image_Graph_Plot_Bar", $Dataset); $Bar->setFillColor("#9db8d2"); $Plot =& $Plotarea->add($Bar); $candidate_connections_sql = self::$stats->getSqlCandidateConnectionsQuery("COUNT(distinct user_mac) AS connections, extract('hour' from timestamp_in) AS hour"); $db->execSql("{$candidate_connections_sql} GROUP BY hour ORDER BY hour", $results, false); if ($results) { foreach ($results as $row) { $Dataset->addPoint($row['hour'] . "h", $row['connections']); } } $Graph->done(); }
/** Return the actual Image data * Classes must override this. * @param $child_html The child method's return value * @return A html fragment */ public function showImageData() { require_once "Image/Graph.php"; $db = AbstractDb::getObject(); $Graph =& Image_Graph::factory("Image_Graph", array(600, 200)); $Plotarea =& $Graph->add(Image_Graph::factory("Image_Graph_Plotarea")); $Dataset =& Image_Graph::factory("Image_Graph_Dataset_Trivial"); $Bar =& Image_Graph::factory("Image_Graph_Plot_Bar", $Dataset); $Bar->setFillColor("#9db8d2"); $Plot =& $Plotarea->add($Bar); $total = 0; $network_constraint = self::$stats->getSqlNetworkConstraint('account_origin'); $date_constraint = self::$stats->getSqlDateConstraint('reg_date'); $db->execSql("SELECT COUNT(users) AS num_users, date_trunc('month', reg_date) AS month FROM users WHERE account_status = " . ACCOUNT_STATUS_ALLOWED . " {$date_constraint} {$network_constraint} GROUP BY date_trunc('month', reg_date) ORDER BY month", $registration_stats, false); if ($registration_stats) { foreach ($registration_stats as $row) { $Dataset->addPoint(substr($row['month'], 0, 7), $row['num_users']); } } $Graph->done(); }
function create_graph_usemap01($width = 700, $height = 160, $fontsize = 7) { $Canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true)); // This is how you get the ImageMap object, // fx. to save map to file (using toHtml()) $Imagemap = $Canvas->getImageMap(); // Create the graph //$Graph =& Image_Graph::factory('graph', array(600, 140)); $Graph =& Image_Graph::factory('graph', $Canvas); // add a TrueType font //$myfont = '/usr/share/fonts/truetype/freefont/FreeSans.ttf'; $myfont = '/usr/share/fonts/truetype/freefont/FreeSerif.ttf'; $Font =& $Graph->addNew('font', $myfont); //$Font =& $Graph->addNew('font', 'Verdana'); //$Font =& $Graph->addNew('font', 'Helvetica'); // set the font size $Font->setSize($fontsize); $Graph->setFont($Font); #return array(&$Graph, &$Font); return $Graph; }
/** * Factory method to create vertical layout. * * See {@link Image_Graph::layoutFactory()} * * @param Image_Graph_Element $part1 The 1st (top) part of the layout * @param Image_Graph_Element $part2 The 2nd (bottom) part of the layout * @param int $percentage The percentage of the layout to split at * (percentage of total width from the top edge) * @return Image_Graph_Layout The newly created layout object * @static */ function &vertical(&$part1, &$part2, $percentage = 50) { $obj =& Image_Graph::layoutFactory('Vertical', $part1, $part2, $percentage); return $obj; }
<?php /** * Usage example for Image_Graph. * * Main purpose: * Somebody liked it :) * * Other: * None specific * * $Id: misc04.php,v 1.2 2005/08/03 21:21:53 nosey Exp $ * * @package Image_Graph * @author Jesper Veggerby <*****@*****.**> */ require_once 'Image/Graph.php'; // create the graph $Graph =& Image_Graph::factory('graph', array(500, 300)); $Plotarea =& $Graph->addNew('plotarea'); $Dataset =& Image_Graph::factory('Image_Graph_Dataset_Random', array(20, 10, 100, true)); $Fill =& Image_Graph::factory('Image_Graph_Fill_Image', './images/audi-tt-coupe.jpg'); $Plotarea->setFillStyle($Fill); $Plot =& $Plotarea->addNew('Image_Graph_Plot_Smoothed_Area', $Dataset); $Plot->setFillColor('white@0.4'); // output the Graph $Graph->done();
/** * Adds an element to the plotarea * * @param Image_Graph_Element $element The element to add * @param int $axis The axis to associate the element with, either * IMAGE_GRAPH_AXIS_X, IMAGE_GRAPH_AXIS_Y, IMAGE_GRAPH_AXIS_Y_SECONDARY * or the shorter string notations 'x', 'y' or 'ysec' (defaults to * IMAGE_GRAPH_AXIS_Y) * @return Image_Graph_Element The added element * @see Image_Graph_Common::add() */ function &add(&$element, $axis = IMAGE_GRAPH_AXIS_Y) { if ($axis == 'x') { $axis = IMAGE_GRAPH_AXIS_X; } if ($axis == 'y') { $axis = IMAGE_GRAPH_AXIS_Y; } if ($axis == 'ysec') { $axis = IMAGE_GRAPH_AXIS_Y_SECONDARY; } if ($axis == IMAGE_GRAPH_AXIS_Y_SECONDARY && $this->_axisYSecondary == null) { $this->_axisYSecondary =& Image_Graph::factory('axis', IMAGE_GRAPH_AXIS_Y_SECONDARY); $this->_axisYSecondary->_setMinimum(0); if ($this->_horizontal) { $this->_axisYSecondary->_transpose = true; } } parent::add($element); if (is_a($element, 'Image_Graph_Plot')) { $element->_setAxisY($axis); // postpone extrema calculation until we calculate coordinates //$this->_setExtrema($element); } elseif (is_a($element, 'Image_Graph_Grid')) { switch ($axis) { case IMAGE_GRAPH_AXIS_X: if ($this->_axisX != null) { $element->_setPrimaryAxis($this->_axisX); if ($this->_axisY != null) { $element->_setSecondaryAxis($this->_axisY); } } break; case IMAGE_GRAPH_AXIS_Y: if ($this->_axisY != null) { $element->_setPrimaryAxis($this->_axisY); if ($this->_axisX != null) { $element->_setSecondaryAxis($this->_axisX); } } break; case IMAGE_GRAPH_AXIS_Y_SECONDARY: if ($this->_axisYSecondary != null) { $element->_setPrimaryAxis($this->_axisYSecondary); if ($this->_axisX != null) { $element->_setSecondaryAxis($this->_axisX); } } break; } } elseif (is_a($element, 'Image_Graph_Axis')) { switch ($element->_type) { case IMAGE_GRAPH_AXIS_X: $this->_axisX =& $element; break; case IMAGE_GRAPH_AXIS_Y: $this->_axisY =& $element; break; case IMAGE_GRAPH_AXIS_Y_SECONDARY: $this->_axisYSecondary =& $element; break; } if ($element->_getMinimum() == $element->_getMaximum()) { $element->_setMinimum(0); $element->_setMaximum(1); } } return $element; }
/** * Generate * Generates the charts from the data passed into it * * @param chart Array of data and labels * * @return Void Doesn't return anything. */ function Generate($chart) { $this->graph->add( $PlotArea =& new Image_Graph_Plotarea() ); $this->graph->_outputImage = false; switch ($chart['chart_type']) { case 'column': // Add grid $PlotArea->addGridY(new Image_Graph_Grid_Lines()); $PlotArea->addGridX(new Image_Graph_Grid_Lines()); $labels = array_shift($chart['chart_data']); $legend_labels = array(); $DataSets = array(); foreach ($chart['chart_data'] as $data) { $Dataset =& new Image_Graph_Dataset_Trivial(); foreach ($data as $key => $value) { if (!is_numeric($value)) { if ($key == 0) { $legend_labels[] = $value; } continue; } $Dataset->addPoint($key, $value); } $DataSets[] =& $Dataset; } $PlotMultiple =& new Image_Graph_Plot_Bar_Multiple($DataSets); $PlotMultiple->spacing(3); $PlotMultiple->setXValueWidth(1); $Plot1 =& $PlotArea->addPlot($PlotMultiple); $noBorder =& new Image_Graph_Line_Solid(); $noBorder->setThickness(0); // create a Y data value marker $Marker =& $Plot1->add(new Image_Graph_Marker_Value(IMAGE_GRAPH_VALUE_Y)); //$Marker->setFillColor(0xFFFFFF); $Marker->setBorderColor(0xFFFFFF); $PointingMarker =& $Plot1->add(new Image_Graph_Marker_Pointing(0,-10, $Marker)); $PointingMarker->setLineStyle($noBorder); $Plot1->setMarker($PointingMarker); $FillArray =& new Image_Graph_Fill_Array(); foreach ($this->colors as $color) { $FillArray->add(new Image_Graph_Fill_Gradient(IMAGE_GRAPH_GRAD_RADIAL, eval("return 0x{$color};"), eval("return 0x{$color};"), 200)); } $Plot1->setFillStyle($FillArray); $AxisX =& $PlotArea->getAxis(IMAGE_GRAPH_AXIS_X); $AxisX->setDataPreprocessor( new Image_Graph_DataPreprocessor_Array( $labels ) ); $thickAxis =& new Image_Graph_Line_Solid(); $thickAxis->setThickness(2); $AxisX->setLineStyle($thickAxis); $AxisX->setLabelInterval(1); $AxisY =& $PlotArea->getAxis(IMAGE_GRAPH_AXIS_Y); $AxisY->setLineStyle($thickAxis); $AxisY->setDataPreprocessor(new Image_Graph_DataPreprocessor_Function("FormatNumber")); $this->graph->done(); $canvas =& $this->graph->_canvas(); $canvas =& $this->DrawTitle($canvas,$this->title,true); $this->DrawLegend($canvas,$legend_labels,'column'); break; // case column case 'pie': $DataSet =& new Image_Graph_Dataset_Trivial(); $Plot1 =& $PlotArea->addPlot(new Image_Graph_Plot_Pie($DataSet)); $points = $chart['chart_data'][1]; $labels = $chart['chart_data'][0]; foreach ($points as $key => $value) { if (!is_numeric($value)) { continue; } $DataSet->addPoint($labels[$key], $value); } $PlotArea->hideAxis(); // create a Y data value marker $Marker =& $Plot1->add(new Image_Graph_Marker_Value(IMAGE_GRAPH_VALUE_X)); $Marker->setFillColor(0xFFFFFF); $Marker->setBorderColor(0xFFFFFF); $PointingMarker =& $Plot1->add(new Image_Graph_Marker_Pointing_Angular(40, $Marker)); $Plot1->setMarker($PointingMarker); $FillArray =& new Image_Graph_Fill_Array(); foreach ($this->colors as $color) { $FillArray->add(new Image_Graph_Fill_Gradient(IMAGE_GRAPH_GRAD_RADIAL, eval("return 0x{$color};"), eval("return 0x{$color};"), 200)); } $Plot1->setFillStyle($FillArray); $Plot1->Radius = 80; $this->graph->done(); $canvas =& $this->graph->_canvas(); $this->DrawLegend($canvas,$labels,'pie'); $canvas =& $this->DrawTitle($canvas,$this->title); break; // case pie } $this->canvas =& $canvas; }
/** Return the actual Image data * Classes must override this. * @param $child_html The child method's return value * @param $param mixed: used for $Graph->done() * @return A html fragment */ public function showImageData($child_html = '', $param = false) { require_once "Image/Graph.php"; $db = AbstractDb::getObject(); $Graph =& Image_Graph::factory("Image_Graph", array(600, 200)); $Plotarea =& $Graph->add(Image_Graph::factory("Image_Graph_Plotarea")); $Dataset =& Image_Graph::factory("Image_Graph_Dataset_Trivial"); $Bar =& Image_Graph::factory("Image_Graph_Plot_Bar", $Dataset); $Bar->setFillColor("#9db8d2"); $Plot =& $Plotarea->add($Bar); $candidate_connections_sql = self::$stats->getSqlCandidateConnectionsQuery("COUNT(DISTINCT connections.user_id||connections.node_id) AS daily_connections, date_trunc('day', timestamp_in) AS date"); $db->execSql("SELECT SUM(daily_connections) AS connections, date_trunc('month', date) AS month FROM ({$candidate_connections_sql} GROUP BY date) AS daily_connections_table GROUP BY month ORDER BY month", $results, false); if ($results != null) { foreach ($results as $row) { /* Cut xxxx-xx-xx xx:xx:Xx to yy-mm */ $Dataset->addPoint(substr($row['month'], 0, 7), $row['connections']); } } $Graph->done($param); unset($Graph, $Plot, $Bar, $Plotarea, $Dataset, $row, $results); }
function get_weekly_volume_graph($userID, $connection) { $beg_date = new Date(); $end_date = new Date(); $wk = array(0, 0, 0, 0, 0, 0, 0); $wk_actual = array(0, 0, 0, 0, 0, 0, 0); $label = array(0, 0, 0, 0, 0, 0, 0); $filename = array("filename" => "/var/www/vanhlebarsoftware/fitlog/graphs/wklygraph.jpg"); // Get current weeks and prior three weeks volume numbers and the next three weeks. $day_of_wk = $beg_date->getDayOfWeek(); $beg_date->addDays(-($day_of_wk - 1) + 21); $end_date->copy($beg_date); $end_date->addDays(6); for ($i = 0; $i < 7; $i++) { // Get the planned volume for this particular week. $query = "SELECT SUM(seconds) AS seconds FROM flmain WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userID . " AND plan_type='p'"; $queryStr = "SELECT SUM(seconds) AS seconds FROM flstrength WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userID . " AND plan_type='p'"; $result = @mysql_query($query, $connection); $resultStr = @mysql_query($query, $connection); if ($result || $resultStr) { $tmp = 0; if ($result) { $row = mysql_fetch_array($result); $tmp = convert_seconds_minutes($row["seconds"]); } if ($resultStr) { $rowStr = mysql_fetch_array($resultStr); $tmp += convert_seconds_minutes($rowStr["seconds"]); } $wk[$i] = $tmp; } else { $wk[$i] = 0; } // Get the actual volume for this particular week. $query = "SELECT SUM(seconds) AS seconds FROM flmain WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userID . " AND plan_type='a'"; $queryStr = "SELECT SUM(seconds) AS seconds FROM flstrength WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userID . " AND plan_type='a'"; $result = @mysql_query($query, $connection); $resultStr = @mysql_query($queryStr, $connection); if ($result || $resultStr) { $tmp = 0; if ($result) { $row = mysql_fetch_array($result); $tmp = convert_seconds_minutes($row["seconds"]); } if ($resultStr) { $rowStr = mysql_fetch_array($resultStr); $tmp += convert_seconds_minutes($rowStr["seconds"]); } $wk_actual[$i] = $tmp; } else { $wk_actual[$i] = 0; } // Create the labels. $label[$i] = $end_date->format("%m/%d"); // Move the dates back by one week. $beg_date->addDays(-7); $end_date->addDays(-7); } for ($i = 0; $i < 7; $i++) { } //Setup the graph. $Graph =& Image_Graph::factory('graph', array(300, 210, TRUE)); $Graph->add(Image_Graph::factory('title', array('Weekly Volume - Actual vs. Planned'), 12)); $Plotarea =& $Graph->addNew('plotarea'); $Dataset =& Image_Graph::factory('dataset'); $Dataset1 =& Image_Graph::factory('dataset'); // Add the actual volume to the graph. $Dataset1->addPoint($label[6], $wk_actual[6]); $Dataset1->addPoint($label[5], $wk_actual[5]); $Dataset1->addPoint($label[4], $wk_actual[4]); $Dataset1->addPoint($label[3], $wk_actual[3]); $Dataset1->addPoint($label[2], $wk_actual[2]); $Dataset1->addPoint($label[1], $wk_actual[1]); $Dataset1->addPoint($label[0], $wk_actual[0]); // Add the planned volume to the graph. $Dataset->addPoint($label[6], $wk[6]); $Dataset->addPoint($label[5], $wk[5]); $Dataset->addPoint($label[4], $wk[4]); $Dataset->addPoint($label[3], $wk[3]); $Dataset->addPoint($label[2], $wk[2]); $Dataset->addPoint($label[1], $wk[1]); $Dataset->addPoint($label[0], $wk[0]); // Plot the actual data to the graph. $Plot =& $Plotarea->addNew('line', &$Dataset); $Plot1 =& $Plotarea->addNew('bar', &$Dataset1); $Plot1->setFillColor('green@.8'); // Set the axis titles. $YAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); $YAxis->setTitle('Minutes', 'vertical'); $XAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X); $XAxis->setTitle("Week", array('angle' => 0)); //Output the finished graph to the graphs directory. $result = $Graph->done($filename); if ($result) { var_dump("error creating graph!"); } }
$Dataset_Rainfall->addPoint('Mar', 48); $Dataset_Rainfall->addPoint('Apr', 42); $Dataset_Rainfall->addPoint('May', 50); $Dataset_Rainfall->addPoint('Jun', 55); $Dataset_Rainfall->addPoint('Jul', 67); $Dataset_Rainfall->addPoint('Aug', 65); $Dataset_Rainfall->addPoint('Sep', 72); $Dataset_Rainfall->addPoint('Oct', 77); $Dataset_Rainfall->addPoint('Nov', 80); $Dataset_Rainfall->addPoint('Dec', 68); $Plot_Rainfall =& $Plotarea_Weather->addNew('bar', array(&$Dataset_Rainfall), IMAGE_GRAPH_AXIS_Y_SECONDARY); $Plot_Rainfall->setLineColor('gray'); $Plot_Rainfall->setFillColor('blue@0.1'); $Plot_Rainfall->setTitle('Average rainfall'); $DataPreprocessor_MM =& Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', '%d mm'); $DataPreprocessor_DegC =& Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', '%d C'); $Marker_Rainfall =& $Plot_Rainfall->addNew('Image_Graph_Marker_Value', IMAGE_GRAPH_VALUE_Y); $Marker_Rainfall->setDataPreprocessor($DataPreprocessor_MM); $PointingMarker_Rainfall =& $Plot_Rainfall->addNew('Image_Graph_Marker_Pointing_Angular', array(20, &$Marker_Rainfall)); $Plot_Rainfall->setMarker($PointingMarker_Rainfall); $AxisX_Weather =& $Plotarea_Weather->getAxis(IMAGE_GRAPH_AXIS_X); $AxisX_Weather->setAxisIntersection('min'); $AxisY_Weather =& $Plotarea_Weather->getAxis(IMAGE_GRAPH_AXIS_Y); $AxisY_Weather->showLabel(IMAGE_GRAPH_LABEL_ZERO); $AxisY_Weather->setDataPreprocessor($DataPreprocessor_DegC); $AxisY_Weather->setTitle('Temperature', 'vertical'); $AxisYsecondary_Weather =& $Plotarea_Weather->getAxis(IMAGE_GRAPH_AXIS_Y_SECONDARY); $AxisYsecondary_Weather->setDataPreprocessor($DataPreprocessor_MM); $AxisYsecondary_Weather->setTitle('Rainfall', 'vertical2'); // output the graph $Graph->done();
// create the graph $Graph =& Image_Graph::factory('graph', array(400, 300)); // add a TrueType font $Font =& $Graph->addNew('font', 'Verdana'); // set the font size to 11 pixels $Font->setSize(8); $Graph->setFont($Font); $Graph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Stacked Bar Chart Sample', 12)), Image_Graph::vertical($Plotarea = Image_Graph::factory('plotarea'), $Legend = Image_Graph::factory('legend'), 90), 5)); $Legend->setPlotarea($Plotarea); // create the dataset $Datasets[] =& Image_Graph::factory('random', array(10, 0, 4, false)); $Datasets[] =& Image_Graph::factory('random', array(10, 0, 4, false)); $Datasets[] =& Image_Graph::factory('random', array(10, 0, 4, false)); // create the 1st plot as smoothed area chart using the 1st dataset $Plot =& $Plotarea->addNew('bar', array($Datasets, 'stacked')); // set a line color $Plot->setLineColor('gray'); // create a fill array $FillArray =& Image_Graph::factory('Image_Graph_Fill_Array'); $FillArray->addColor('blue@0.2'); $FillArray->addColor('yellow@0.2'); $FillArray->addColor('green@0.2'); // set a standard fill style $Plot->setFillStyle($FillArray); // create a Y data value marker $Marker =& $Plot->addNew('Image_Graph_Marker_Value', IMAGE_GRAPH_VALUE_Y); // and use the marker on the 1st plot $Plot->setMarker($Marker); $Plot->setDataSelector(Image_Graph::factory('Image_Graph_DataSelector_NoZeros')); // output the Graph $Graph->done();
/** Function to render the Horizontal Graph * Portions created by vtiger are Copyright (C) vtiger. * All Rights Reserved. * Contributor(s): ______________________________________.. */ function horizontal_graph($referdata, $refer_code, $width, $height, $left, $right, $top, $bottom, $title, $target_val, $cache_file_name, $html_image_name) { global $log, $root_directory, $lang_crm, $theme; //We'll be getting the values in the form of a string separated by commas $datay = explode("::", $referdata); // The datay values $datax = explode("::", $refer_code); // The datax values // The links values are given as string in the encoded form, here we are decoding it $target_val = urldecode($target_val); $target = explode("::", $target_val); $alts = array(); $temp = array(); for ($i = 0; $i < count($datax); $i++) { $name = $datax[$i]; $pos = substr_count($name, " "); // JFV : prevent utf-8 char garbled and display percentage correctly global $default_charset; $sum = 0; for ($j = 0; $j < count($datay); $j++) { $sum += $datay[$j]; } $alts[] = htmlentities($name, ENT_QUOTES, $default_charset) . " = " . sprintf('%0.1f%%', 100 * $datay[$i] / $sum); // $alts[]=htmlentities($name)."=%d"; // JFV END //If the daatx value of a string is greater, adding '\n' to it so that it'll cme inh 2nd line if (strlen($name) >= 14) { $name = substr($name, 0, 44); } if ($pos >= 2) { $val = explode(" ", $name); $n = count($val) - 1; $x = ""; for ($j = 0; $j < count($val); $j++) { if ($j != $n) { $x .= " " . $val[$j]; } else { $x .= "@#" . $val[$j]; } } $name = $x; } $name = str_replace("@#", "\n", $name); $temp[] = $name; } $datax = $temp; //datay is the values //datax is the status // Set the basic parameters of the graph $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true)); $imagemap = $canvas->getImageMap(); $graph =& Image_Graph::factory('graph', $canvas); $font =& $graph->addNew('font', calculate_font_name($lang_crm)); // set the font size to 12 $font->setSize(8); if ($theme == "blue") { $font_color = "#212473"; } else { $font_color = "#000000"; } $font->setColor($font_color); $graph->setFont($font); $titlestr =& Image_Graph::factory('title', array($title, 8)); $plotarea =& Image_Graph::factory('plotarea', array('axis', 'axis', 'horizontal')); $graph->add(Image_Graph::vertical($titlestr, $plotarea, 5)); // Now create a bar plot $max = 0; // To create unique lables we need to keep track of lable name and its count $uniquex = array(); $xlabels = array(); $dataset =& Image_Graph::factory('dataset'); if ($theme == 'woodspice') { $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED, '#804000', 'white')); } elseif ($theme == 'bluelagoon') { $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED, 'blue', 'white')); } elseif ($theme == 'softed') { $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED, 'blue', 'white')); } else { $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED, 'black', 'white')); } for ($i = 0; $i < count($datay); $i++) { $x = 1 + 2 * $i; if ($datay[$i] >= $max) { $max = $datay[$i]; } $dataset->addPoint($x, $datay[$i], array('url' => $target[$i], 'alt' => $alts[$i])); // build the xaxis label array to allow intermediate ticks $xlabels[$x] = $datax[$i]; $xlabels[$x + 1] = ''; // To have unique names even in case of duplicates let us add the id $datax_appearance = $uniquex[$datax[$i]]; if ($datax_appearance == null) { $uniquex[$datax[$i]] = 1; } else { $xlabels[$x] = $datax[$i] . ' [' . $datax_appearance . ']'; $uniquex[$datax[$i]] = $datax_appearance + 1; } } $bplot =& $plotarea->addNew('bar', $dataset); $bplot->setFillStyle($fill); //You can change the width of the bars if you like $bplot->setBarWidth(50 / count($datax), "%"); $bplot->setPadding(array('top' => 10)); // We want to display the value of each bar at the top //$bplot->value->Show(); //$bplot->value->SetFont(FF_FONT2,FS_BOLD,12); //$bplot->value->SetAlign('left','center'); //$bplot->value->SetColor("black","gray4"); //$bplot->value->SetFormat('%d'); //$graph->SetBackgroundGradient('#E5E5E5','white',GRAD_VER,BGRAD_PLOT); $bplot->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_HORIZONTAL, 'white', 'white'))); //$bplot->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_HORIZONTAL, 'white', '#E5E5E5'))); //$bplot->SetFillGradient("navy","lightsteelblue",GRAD_MIDVER); //$graph->SetFrame(false); //$graph->SetMarginColor('cadetblue2'); //$graph->ygrid->SetFill(true,'azure1','azure2'); //$graph->xgrid->Show(); // Add the bar to the graph //$graph->Add($bplot); // Setup title //$titlestr->setText($title); // Setup X-axis $xaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X); $yaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); $yaxis->setFontSize(10); // Invert X-axis and put Y-axis at bottom $xaxis->setInverted(true); $yaxis->setAxisIntersection('max'); // set grid $gridY =& $plotarea->addNew('line_grid', IMAGE_GRAPH_AXIS_Y); $gridY->setLineColor('#FFFFFF@0.5'); $gridY2 =& $plotarea->addNew('bar_grid', null, IMAGE_GRAPH_AXIS_Y); $gridY2->setFillColor('#FFFFFF@0.2'); // Add some grace to y-axis so the bars doesn't go // all the way to the end of the plot area $yaxis->forceMaximum(round($max * 1.1 + 0.5)); $ticks = get_tickspacing(round($max * 1.1 + 0.5)); // First make the labels look right $yaxis->setLabelInterval($ticks[0]); $yaxis->setTickOptions(-5, 0); $yaxis->setLabelInterval($ticks[1], 2); $yaxis->setTickOptions(-2, 0, 2); // Create the xaxis labels $array_data =& Image_Graph::factory('Image_Graph_DataPreprocessor_Array', array($xlabels)); // The fix the tick marks $xaxis->setDataPreprocessor($array_data); $xaxis->forceMinimum(0); $xaxis->forceMaximum(2 * count($datay)); $xaxis->setLabelInterval(1); $xaxis->setTickOptions(0, 0); $xaxis->setLabelInterval(2, 2); $xaxis->setTickOptions(5, 0, 2); // set markers $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y); $marker->setFillColor('000000@0.0'); $marker->setBorderColor('000000@0.0'); $marker->setFontSize(10); // shift markers 10 pix right $marker_pointing =& $graph->addNew('Image_Graph_Marker_Pointing', array(40, 0, &$marker)); $marker_pointing->setLineColor('000000@0.0'); $bplot->setMarker($marker_pointing); //Getting the graph in the form of html page $img = $graph->done(array('tohtml' => true, 'border' => 0, 'filename' => $cache_file_name, 'filepath' => '', 'urlpath' => '')); save_image_map($cache_file_name . '.map', $img); return $img; }
* @link http://pear.php.net/package/Image_Graph */ require_once 'Image/Graph.php'; // create the graph $Graph =& Image_Graph::factory('graph', array(800, 600)); // add a TrueType font $Font =& $Graph->addNew('ttf_font', 'Verdana'); // set the font size to 7 pixels $Font->setSize(7); $Graph->setFont($Font); // create the plotarea $Graph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Testing Changing Axis Label Intervals (Bar Charts also test label distance)', 10)), $Matrix = Image_Graph::factory('Image_Graph_Layout_Matrix', array(4, 4)), 5)); $DS[0] =& Image_Graph::factory('dataset', array(array(0 => 1, 1 => 2, 2 => 0, 3 => 1, 4 => 4))); $DS[1] =& Image_Graph::factory('dataset', array(array('A' => 1, 'B' => 2, 'C' => 0, 'D' => 1, 'E' => 4))); $DS[2] =& Image_Graph::factory('dataset', array(array(0 => 1, 1 => 2, 2 => -2, 3 => 1, 4 => 4))); $DS[3] =& Image_Graph::factory('dataset', array(array('A' => 1, 'B' => 2, 'C' => -2, 'D' => 1, 'E' => 4))); for ($row = 0; $row < 4; $row++) { for ($col = 0; $col < 4; $col++) { if (isset($DS[$col])) { $Plotarea =& $Matrix->getEntry($row, $col); $AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); $AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X); if ($row > 2) { $AxisX->setLabelInterval(3); $AxisX->setTitle('"Odd" interval'); } elseif ($row > 0) { $AxisX->setLabelInterval(2); $AxisX->setTitle('Changed interval'); } else { $AxisX->setTitle('Default interval'); }
function get_weekly_volume_graph() { global $wpdb; global $userdata; get_currentuserinfo(); $beg_date = new Date(); $end_date = new Date(); $wk = array(0, 0, 0, 0); $label = array(0, 0, 0, 0); $filename = array("filename" => "/var/www/vanhlebarsoftware/wp-content/plugins/fitnesslog/graphs/wklygraph.png"); // Get current weeks and prior three weeks volume numbers. $day_of_wk = $beg_date->getDayOfWeek(); $beg_date->addDays(-($day_of_wk - 1)); $end_date->copy($beg_date); $end_date->addDays(6); for ($i = 0; $i < 4; $i++) { $query = "SELECT user_id, SUM(seconds) AS seconds FROM " . $wpdb->prefix . "flmain WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userdata->ID . " GROUP BY user_id"; $result = $wpdb->get_results($query, ARRAY_A); if ($result) { foreach ($result as $row) { $wk[$i] = convert_seconds_minutes($row["seconds"]); } } else { $wk[$i] = 0; } // Add any strength training that we have done to the total. $query = "SELECT user_id, SUM(seconds) AS seconds FROM " . $wpdb->prefix . "flstrength WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userdata->ID . " GROUP BY user_id"; $result = $wpdb->get_results($query, ARRAY_A); if ($result) { foreach ($result as $row) { $wk[$i] = $wk[$i] + convert_seconds_minutes($row["seconds"]); } } // Create the labels. $label[$i] = $end_date->format("%m/%d"); // Move the dates back by one week. $beg_date->addDays(-7); $end_date->addDays(-7); } //Setup the graph. $Graph =& Image_Graph::factory('graph', array(175, 175), true); $Plotarea =& $Graph->addNew('plotarea'); $Dataset =& Image_Graph::factory('dataset'); $Dataset->addPoint($label[3], $wk[3]); $Dataset->addPoint($label[2], $wk[2]); $Dataset->addPoint($label[1], $wk[1]); $Dataset->addPoint($label[0], $wk[0]); $Plot =& $Plotarea->addNew('bar', &$Dataset); $Plot->setFillColor('green'); $YAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); $YAxis->setTitle('Minutes', 'vertical'); $XAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X); // $XAxis->setFontAngle( "vertical" ); $XAxis->setTitle("Week", array('angle' => 0)); //Output the finished graph to the graphs directory. $result = $Graph->done($filename); if ($result) { var_dump("error creating graph!"); } }
$Plot2->setLineColor('blue'); $Plot3->setLineColor('red'); $Plot2->setFillColor('blue@0.1'); $Plot3->setFillColor('red@0.1'); $Marker =& $Plot1->addNew('Image_Graph_Marker_Value', IMAGE_GRAPH_VALUE_Y); //$Marker->setLabelInterval(2); $PointingMarker =& $Plot1->addNew('Image_Graph_Marker_Pointing_Angular', array(30, &$Marker)); $PointingMarker->setFillColor('green@0.1'); $Plot1->setMarker($PointingMarker); $Marker->setDataPreProcessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Function', 'currencyformat')); $Marker->setFontSize(8); } //$FillerLine =& $Plotarea->addNew('Image_Graph_Plot_Area', array(&$Fillerset)); //$FillerLine->setFillColor('blue@0.0'); //$FillerLine->setLineColor('lightsteelblue@0.0'); //$FillerLine->setTitle(''); //$FillerLine->hide(); if ($style != 'tiny') { $Legend =& $Plotarea->addNew('legend'); $Legend->setFillColor('white@0.2'); $Legend->setFillStyle(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'lightsteelblue@0.2', 'white@0.2'))); $Legend->setLineColor('gray@0.7'); $Legend->setFontSize(8); $Legend->showShadow('gray@0.2', 6); } $Plot1->setTitle('Total Approved'); $Plot1->setLineColor('green'); //$Plot3->setLineColor('green'); $Graph->done(); } include "includes/footer.php";
// will be yellow and the "higher" the value the more red it will be, ie a "fire" effect $Plot1->setFillStyle(Image_Graph::factory('Image_Graph_Fill_Image', './images/mountain.jpg')); // create a Y data value marker $Marker =& $Plot1->addNew('Image_Graph_Marker_Value', IMAGE_GRAPH_PCT_Y_MAX); // fill it with white $Marker->setFillColor('white'); // and use black border $Marker->setBorderColor('black'); // create a pin-point marker type $PointingMarker =& $Plot1->addNew('Image_Graph_Marker_Pointing_Angular', array(20, &$Marker)); // and use the marker on the 1st plot $Plot1->setMarker($PointingMarker); // format value marker labels as percentage values $Marker->setDataPreProcessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', '%0.1f%%')); // create the 2nd dataset $Dataset2 =& Image_Graph::factory('random', array(8, 30, 80, false)); // create the 1st plot as smoothed area chart using the 1st dataset $Plot2 =& $Plotarea->addNew('bar', array(&$Dataset2)); // create a vertical gradient fill using red and yellow, ie bottom of graph // will be yellow and the 'higher' the value the more red it will be, ie a 'fire' effect $Plot2->setFillColor('orange@0.6'); // Show arrow heads on the axis $AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X); $AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); $AxisX->showArrow(); $AxisY->showArrow(); $AxisX->setDataPreProcessor(Image_Graph::factory('Image_Graph_DataPreprocessor_RomanNumerals')); $AxisY->setDataPreProcessor(Image_Graph::factory('Image_Graph_DataPreprocessor_NumberText')); $AxisY->forceMinimum(10); // output the Graph $Graph->done();
/** Function to render the Horizontal Graph */ function pie_chart($referdata, $refer_code, $width, $height, $left, $right, $top, $bottom, $title, $target_val, $cache_file_name, $html_image_name) { global $log, $root_directory, $lang_crm, $theme; //We'll be getting the values in the form of a string separated by commas $datay = explode("::", $referdata); // The datay values $datax = explode("::", $refer_code); // The datax values $target_val = urldecode($target_val); $target = explode("::", $target_val); $alts = array(); $temp = array(); for ($i = 0; $i < count($datax); $i++) { $name = $datax[$i]; $pos = substr_count($name, " "); $alts[] = htmlentities($name) . "=%d"; //If the datax value of a string is greater, adding '\n' to it so that it'll come in 2nd line if (strlen($name) >= 14) { $name = substr($name, 0, 34); } if ($pos >= 2) { $val = explode(" ", $name); $n = count($val) - 1; $x = ""; for ($j = 0; $j < count($val); $j++) { if ($j != $n) { $x .= " " . $val[$j]; } else { $x .= "@#" . $val[$j]; } } $name = $x; } $name = str_replace("@#", "\n", $name); $temp[] = $name; } $datax = $temp; if ($theme == "blue") { $font_color = "#212473"; } else { $font_color = "#000000"; } $width = $width + 140; $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true)); $imagemap = $canvas->getImageMap(); $graph =& Image_Graph::factory('graph', $canvas); $font =& $graph->addNew('font', calculate_font_name($lang_crm)); // set the font size to 11 pixels $font->setSize(8); $font->setColor($font_color); $graph->setFont($font); // create the plotarea layout $title =& Image_Graph::factory('title', array($title, 10)); $plotarea =& Image_Graph::factory('plotarea', array('category', 'axis')); $footer =& Image_Graph::factory('title', array('Footer', 8)); $legend_box =& Image_Graph::factory('legend'); $graph->add(Image_Graph::vertical($title, $plotarea, 5)); // To create unique lables we need to keep track of lable name and its count $uniquex = array(); // Generate colours $colors = color_generator(count($datay), '#33DDFF', '#3322FF'); $dataset =& Image_Graph::factory('dataset'); $fills =& Image_Graph::factory('Image_Graph_Fill_Array'); $sum = 0; for ($i = 0; $i < count($datay); $i++) { if (isset($_REQUEST['display_view']) && $_REQUEST['display_view'] == 'MATRIX') { $datax[$i] = trim($datax[$i]); if (strlen($datax[$i]) <= 10) { $datax[$i] = $datax[$i]; } else { $datax[$i] = substr($datax[$i], 0, 10) . ".."; } } // To have unique names even in case of duplicates let us add the id $datalabel = $datax[$i]; $datax_appearance = $uniquex[$datax[$i]]; if ($datax_appearance == null) { $uniquex[$datax[$i]] = 1; } else { $datalabel = $datax[$i] . ' [' . $datax_appearance . ']'; $uniquex[$datax[$i]] = $datax_appearance + 1; } $dataset->addPoint($datalabel, $datay[$i], array('url' => $target[$i], 'alt' => $alts[$i])); $sum += $datay[$i]; $fills->addColor($colors[$i]); } // create an array with % values $pcvalues = array(); for ($i = 0; $i < count($datay); $i++) { $pcvalues[$datay[$i]] = sprintf('%0.1f%%', 100 * $datay[$i] / $sum); } // create the pie chart and associate the filling colours $gbplot =& $plotarea->addNew('pie', $dataset); $plotarea->setPadding(array('top' => 20, 'bottom' => 0, 'left' => 0, 'right' => 50)); $plotarea->hideAxis(); $gbplot->setFillStyle($fills); // format the data values $marker_array =& Image_Graph::factory('Image_Graph_DataPreprocessor_Array', array($pcvalues)); // set markers $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y); $marker->setDataPreprocessor($marker_array); $marker->setFillColor('#FFFFFF'); $marker->setBorderColor($font_color); $marker->setFontColor($font_color); $marker->setFontSize(8); $pointingMarker =& $graph->addNew('Image_Graph_Marker_Pointing_Angular', array(20, &$marker)); $gbplot->setMarker($pointingMarker); // set legend $legend_box =& $plotarea->addNew('legend'); $legend_box->setPadding(array('top' => 20, 'bottom' => 0, 'left' => 0, 'right' => 0)); $legend_box->setFillColor('#F5F5F5'); $legend_box->showShadow(); $img = $graph->done(array('tohtml' => true, 'border' => 0, 'filename' => $cache_file_name, 'filepath' => '', 'urlpath' => '')); save_image_map($cache_file_name . '.map', $img); return $img; }
* @link http://pear.php.net/package/Image_Graph */ require_once 'Image/Graph.php'; // create the graph $Graph =& Image_Graph::factory('graph', array(600, 400)); // add a TrueType font $Font =& $Graph->addNew('ttf_font', 'Verdana'); // set the font size to 11 pixels $Font->setSize(7); $Graph->setFont($Font); // create the plotarea $Graph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Testing Area Plots', 10)), $Matrix = Image_Graph::factory('Image_Graph_Layout_Matrix', array(2, 2, false)), 5)); for ($i = 0; $i < 2; $i++) { for ($j = 0; $j < 2; $j++) { $Matrix->setEntry($i, $j, Image_Graph::factory('plotarea', array('Image_Graph_Axis_Category', 'axis', 'horizontal'))); } } $DS[0][0] =& Image_Graph::factory('dataset', array(array('A' => 1, 'B' => 2, 'C' => 0, 'D' => 4, 'E' => 3))); $DS[0][1] =& Image_Graph::factory('dataset', array(array('A' => 1, 'B' => -2, 'C' => 1, 'D' => 3, 'E' => -1))); $DS[1][0] =& Image_Graph::factory('dataset', array(array('A' => 2, 'B' => 3, 'C' => 1, 'D' => 4, 'E' => 2))); $DS[1][1] =& Image_Graph::factory('dataset', array(array('A' => -1, 'B' => -3, 'C' => -2, 'D' => -4, 'E' => -1))); for ($row = 0; $row < 2; $row++) { for ($col = 0; $col < 2; $col++) { if (isset($DS[$row][$col])) { $Plotarea =& $Matrix->getEntry($row, $col); $Plot =& $Plotarea->addNew('impulse', $DS[$row][$col]); $Plot->setLineColor('red'); } } } $Graph->done();
/** * Factory method to create the Image_Simple_Graph object. * * @param int $width ??? * @param int $height ??? * @param ??? $plotType ??? * @param ??? $data ??? * @param string $title ??? * @param string $lineColor ??? * @param string $fillColor ??? * @param ??? $font ??? * * @return Image_Simple_Graph */ function &factory($width, $height, $plotType, $data, $title, $lineColor = 'black', $fillColor = 'white', $font = false) { $obj =& Image_Graph::factory('Image_Graph_Simple', array($width, $height, $plotType, $data, $title, $lineColor, $fillColor, $font)); return $obj; }
* * $Id: plot_step.php,v 1.3 2005/08/03 21:21:52 nosey Exp $ * * @package Image_Graph * @author Jesper Veggerby <*****@*****.**> */ require_once 'Image/Graph.php'; // create the graph $Graph =& Image_Graph::factory('graph', array(400, 300)); // add a TrueType font $Font =& $Graph->addNew('font', 'Verdana'); // set the font size to 11 pixels $Font->setSize(8); $Graph->setFont($Font); $Graph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Step Chart Sample', 12)), Image_Graph::vertical($Plotarea = Image_Graph::factory('plotarea'), $Legend = Image_Graph::factory('legend'), 90), 5)); $Legend->setPlotarea($Plotarea); // create the dataset $Dataset[] =& Image_Graph::factory('random', array(10, 2, 5, false)); $Dataset[] =& Image_Graph::factory('random', array(10, 2, 5, false)); $Dataset[] =& Image_Graph::factory('random', array(10, 2, 5, false)); // create the 1st plot as smoothed area chart using the 1st dataset $Plot =& $Plotarea->addNew('Image_Graph_Plot_Step', array($Dataset, 'stacked')); // set a line color $Plot->setLineColor('gray'); $Fill =& Image_Graph::factory('Image_Graph_Fill_Array'); $Fill->addColor('red@0.2'); $Fill->addColor('blue@0.2'); $Fill->addColor('green@0.2'); $Plot->setFillStyle($Fill); // output the Graph $Graph->done();
require_once 'Image/Graph.php'; // create the graph $Graph =& Image_Graph::factory('graph', array(800, 600)); // add a TrueType font $Font =& $Graph->addNew('ttf_font', 'Verdana'); // set the font size to 11 pixels $Font->setSize(7); $Graph->setFont($Font); // create the plotarea $Graph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Testing Secondary Axis Intersection', 10)), $Matrix = Image_Graph::factory('Image_Graph_Layout_Matrix', array(3, 3)), 5)); $DS[0] =& Image_Graph::factory('dataset', array(array('0' => 1, '1' => 2, '2' => 0))); $DS[1] =& Image_Graph::factory('dataset', array(array('0' => -1, '1' => 2, '2' => 1))); $DS[2] =& Image_Graph::factory('dataset', array(array('0' => 1, '1' => 3, '2' => 2))); $DS2[0] =& Image_Graph::factory('dataset', array(array('0' => -1, '1' => 2, '2' => 1))); $DS2[1] =& Image_Graph::factory('dataset', array(array('0' => 1, '1' => 3, '2' => 2))); $DS2[2] =& Image_Graph::factory('dataset', array(array('0' => 1, '1' => 2, '2' => 1))); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { if (isset($DS[$col])) { $Plotarea =& $Matrix->getEntry($row, $col); $AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); $AxisY->setLineColor('silver'); $AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X); $AxisX->setAxisIntersection($row < 1 ? 0 : 1, IMAGE_GRAPH_AXIS_Y_SECONDARY); $AxisX->setTitle("Intersect at\ny2=" . ($row < 1 ? '0' : '1')); $Plot =& $Plotarea->addNew('line', $DS2[$col]); $Plot->setLineColor('red@0.1'); $Plot2 =& $Plotarea->addNew('line', $DS[$col], IMAGE_GRAPH_AXIS_Y_SECONDARY); $Plot2->setLineColor('green'); $Plotarea->setBackgroundColor('blue@0.2'); $AxisYsec =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y_SECONDARY);
/** * Creates pie chart image of opportunities by lead_source. * param $datax- the sales stage data to display in the x-axis * param $datay- the sum of opportunity amounts for each opportunity in each sales stage * to display in the y-axis * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. * All Rights Reserved.. * Contributor(s): ______________________________________.. */ function pipeline_by_lead_source($legends = array('foo', 'bar'), $user_id = array('1'), $cache_file_name = 'a_file', $refresh = true, $width = 900, $height = 500) { global $log, $current_user; $log->debug("Entering pipeline_by_lead_source(" . $legends . ") method ..."); global $app_strings, $lang_crm, $current_module_strings, $log, $charset, $tmp_dir; global $theme; include_once 'Image/Graph.php'; include_once 'Image/Canvas.php'; $font = calculate_font_name($lang_crm); if (!file_exists($cache_file_name) || !file_exists($cache_file_name . '.map') || $refresh == true) { $log =& LoggerManager::getLogger('opportunity charts'); $log->debug("starting pipeline chart"); $log->debug("legends is:"); $log->debug($legends); $log->debug("user_id is: "); $log->debug($user_id); $log->debug("cache_file_name is: {$cache_file_name}"); //Now do the db queries //query for opportunity data that matches $legends and $user $where = ""; //build the where clause for the query that matches $datax $count = count($legends); if ($count > 0) { $where .= " leadsource in ( "; $ls_i = 0; foreach ($legends as $key => $value) { if ($ls_i != 0) { $where .= ", "; } $where .= "'" . addslashes($key) . "'"; $ls_i++; } $where .= ")"; } $opp = new Potentials(); $opp_list = $opp->get_full_list("vtiger_potential.amount DESC, vtiger_potential.closingdate DESC", $where); //build pipeline by lead source data $total = 0; $count = array(); $sum = array(); if (isset($opp_list)) { foreach ($opp_list as $record) { if (!isset($sum[$record->column_fields['leadsource']])) { $sum[$record->column_fields['leadsource']] = 0; } if (isset($record->column_fields['amount']) && isset($record->column_fields['leadsource'])) { // Strip all non numbers from this string. $amount = CurrencyField::convertFromMasterCurrency(preg_replace('/[^0-9]/', '', floor($record->column_fields['amount'])), $current_user->conv_rate); $sum[$record->column_fields['leadsource']] = $sum[$record->column_fields['leadsource']] + $amount / 1000; if (isset($count[$record->column_fields['leadsource']])) { $count[$record->column_fields['leadsource']]++; } else { $count[$record->column_fields['leadsource']] = 1; } $total = $total + $amount / 1000; } } } $visible_legends = array(); $data = array(); $aTargets = array(); $aAlts = array(); foreach ($legends as $lead_source_key => $lead_source_translation) { if (isset($sum[$lead_source_key])) { array_push($data, $sum[$lead_source_key]); if ($lead_source_key != '') { array_push($visible_legends, $lead_source_translation); } else { // put none in if the vtiger_field is blank. array_push($visible_legends, $current_module_strings['NTC_NO_LEGENDS']); } $cvid = getCvIdOfAll("Potentials"); array_push($aTargets, "index.php?module=Potentials&action=ListView&leadsource=" . urlencode($lead_source_key) . "&query=true&type=dbrd&viewname=" . $cvid); array_push($aAlts, $count[$lead_source_key] . " " . $current_module_strings['LBL_OPPS_IN_LEAD_SOURCE'] . " {$lead_source_translation}\t"); } } $log->debug("sum is:"); $log->debug($sum); $log->debug("count is:"); $log->debug($count); $log->debug("total is: {$total}"); if ($total == 0) { $log->debug("Exiting pipeline_by_lead_source method ..."); return $current_module_strings['ERR_NO_OPPS']; } if ($theme == "blue") { $font_color = "#212473"; } else { $font_color = "#000000"; } $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true)); $imagemap = $canvas->getImageMap(); $graph =& Image_Graph::factory('graph', $canvas); $font =& $graph->addNew('font', calculate_font_name($lang_crm)); // set the font size to 11 pixels $font->setSize(8); $font->setColor($font_color); $graph->setFont($font); // create the plotarea layout $title =& Image_Graph::factory('title', array('Test', 10)); $plotarea =& Image_Graph::factory('plotarea', array('category', 'axis')); $footer =& Image_Graph::factory('title', array('Footer', 8)); $graph->add(Image_Graph::vertical($title, Image_Graph::vertical($plotarea, $footer, 90), 5)); // Generate colours $colors = color_generator(count($visible_legends), '#33CCFF', '#3322FF'); $index = 0; $dataset =& Image_Graph::factory('dataset'); $fills =& Image_Graph::factory('Image_Graph_Fill_Array'); foreach ($visible_legends as $legend) { $dataset->addPoint($legend, $data[$index], array('url' => $aTargets[$index], 'alt' => $aAlts[$index])); $fills->addColor($colors[$index]); $log->debug('point =' . $legend . ',' . $data[$index]); $index++; } // create the pie chart and associate the filling colours $gbplot =& $plotarea->addNew('pie', $dataset); $plotarea->hideAxis(); $gbplot->setFillStyle($fills); // Setup title $titlestr = $current_module_strings['LBL_TOTAL_PIPELINE'] . $current_user->currency_symbol . $total . $app_strings['LBL_THOUSANDS_SYMBOL']; //$titlestr = $current_module_strings['LBL_TOTAL_PIPELINE'].$current_user->currency_symbol.$total; $title->setText($titlestr); // format the data values $valueproc =& Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', $current_user->currency_symbol . "%d"); // set markers $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y); $marker->setDataPreprocessor($valueproc); $marker->setFillColor('#FFFFFF'); $marker->setBorderColor($font_color); $marker->setFontColor($font_color); $marker->setFontSize(8); $pointingMarker =& $graph->addNew('Image_Graph_Marker_Pointing_Angular', array(20, &$marker)); $gbplot->setMarker($pointingMarker); // set legend $legend_box =& $plotarea->addNew('legend'); $legend_box->setPadding(array('top' => 20, 'bottom' => 0, 'left' => 0, 'right' => 0)); $legend_box->setFillColor('#F5F5F5'); $legend_box->showShadow(); $subtitle = $current_module_strings['LBL_OPP_SIZE'] . $current_user->currency_symbol . $current_module_strings['LBL_OPP_SIZE_VALUE']; $footer->setText($subtitle); $footer->setAlignment(IMAGE_GRAPH_ALIGN_TOP_LEFT); $imgMap = $graph->done(array('tohtml' => true, 'border' => 0, 'filename' => $cache_file_name, 'filepath' => './', 'urlpath' => '')); //$imgMap = htmlspecialchars($output); save_image_map($cache_file_name . '.map', $imgMap); } else { $imgMap_fp = fopen($cache_file_name . '.map', "rb"); $imgMap = fread($imgMap_fp, filesize($cache_file_name . '.map')); fclose($imgMap_fp); } $fileModTime = filemtime($cache_file_name . '.map'); $return = "\n{$imgMap}"; $log->debug("Exiting pipeline_by_lead_source method ..."); return $return; }
/** * Creates an object from the class and adds it to the objects element list. * * Creates an object from the class specified and adds it to the objects * element list. If only one parameter is required for the constructor of * the class simply pass this parameter as the $params parameter, unless the * parameter is an array or a reference to a value, in that case you must * 'enclose' the parameter in an array. Similar if the constructor takes * more than one parameter specify the parameters in an array. * * @see Image_Graph::factory() * @param string $class The class for the object * @param mixed $params The paramaters to pass to the constructor * @return Image_Graph_Common The new Image_Graph_element */ function &addNew($class, $params = null, $additional = false) { include_once 'Image/Graph.php'; $element =& Image_Graph::factory($class, $params); if ($additional === false) { $obj =& $this->add($element); } else { $obj =& $this->add($element, $additional); } return $obj; }
$Plot->setMarker($Marker); // create the 2nd plot ('defects / 1000 units') as a line plot and associate // it with the secondary y-axis (implicitly this creates a y-axis of the class // Image_Graph_Axis) $Plot2 =& $Plotarea->addNew('line', array(&$Dataset2), IMAGE_GRAPH_AXIS_Y_SECONDARY); // set the plot title $Plot2->setTitle('Defects'); // and line style $Plot2->setLineColor('gray@0.8'); // create a value marker to display the actual y-values $Marker =& $Graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y); // and make the line plot use this $Plot2->setMarker($Marker); // make the marker print using font-size 7 $Marker->setFontSize(7); // ... in blue $Marker->setFontColor('blue'); // get the y-axis $AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); // and create a datapreprocessor to make the labels print out as percentage valuexs $AxisY->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', '%0.0f%%')); // force a maximum on the y-axis to 105 $AxisY->forceMaximum(105); // set the axis title and make it display vertically ('vertical' = down->up) $AxisY->setTitle('Popularity', 'vertical'); // get the secondary y-axis $AxisYsec =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y_SECONDARY); // set the axis title and make it display vertically ('vertical2' = up->down) $AxisYsec->setTitle('Defects / 1000 units', 'vertical2'); // output the Graph $Graph->done();
/** * The final "child" implementation of the parental abstract method, * to produce a graph of the data for delivery statistics. * * @param array $aGraphFilterArray Filter array ...? * @return string Complete link ...? */ function showGraph($aGraphFilterArray) { global $conf, $GraphFile; if (!extension_loaded('gd')) { // GD isn't enabled in php install return 'noGD'; } if (isset($this->aStatsData)) { // Put sum_clicks on right axis only when there are $aTempGraph = array_flip($aGraphFilterArray); if (isset($aTempGraph['sum_clicks']) && !isset($aTempGraph['sum_ctr'])) { $aClickKey = $aTempGraph['sum_clicks']; } else { $aClickKey = false; } /** * stat display fonfiguration array to determine how the data is visually displayed on the graph * field line: if set to Image_Graph_Plot_Bar, then it will display as a Bar. Otherwise it will be a line (can be dotted, dashed or solid) * field params: set the color of the line * field axis: determine whether data is connected with left-hand axis (1) or righthand-axis (2) */ $aFieldStyle = array('sum_requests' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#33cc00', 'transpartent'), 'axis' => '1'), 'sum_views' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#006699', 'transparent'), 'axis' => '1'), 'sum_clicks' => array('line' => 'Image_Graph_Plot_Bar', 'params' => array('#333333', 'transparent'), 'axis' => '1', 'background' => 'white@0.3'), 'sum_ctr' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('cadetblue', 'transparent'), 'axis' => '2', 'background' => 'white@0.3'), 'sum_conversions' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#hh00hh', 'transparent'), 'axis' => '1'), 'sum_conversions_pending' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#cccccc', 'transparent'), 'axis' => '1'), 'sum_sr_views' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#0000cc', 'transparent'), 'axis' => '2', 'background' => 'white@0.3'), 'sum_sr_clicks' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#cc0000', 'transparent'), 'axis' => '2', 'background' => 'white@0.3'), 'sum_revenue' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#120024', 'transparent'), 'axis' => '1'), 'sum_cost' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#123456', 'transparent'), 'axis' => '1'), 'sum_bv' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#654321', 'transparent'), 'axis' => '1'), 'sum_revcpc' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#666666', 'transparent'), 'axis' => '1'), 'sum_costcpc' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#343434', 'transparent'), 'axis' => '1')); if ($aClickKey) { $aFieldStyle[$aGraphFilterArray[$aClickKey]]['axis'] = '2'; } if (function_exists("imagejpeg")) { $imageFormat = 'jpg'; } if (function_exists("imagepng")) { $imageFormat = 'png'; } // Create the graph $oCanvas =& Image_Canvas::factory($imageFormat, array('width' => 800, 'height' => 400, 'usemap' => true)); $oImagemap = $oCanvas->getImageMap(); $oGraph =& Image_Graph::factory('graph', $oCanvas); if (function_exists('ImageTTFBBox')) { // Add a TrueType font $Font =& $oGraph->addNew('ttf_font', 'arial.ttf'); // Set the font size to 11 pixels $Font->setSize(8); $Font->setColor('#444444'); $oGraph->setFont($Font); } $oPlotarea =& $oGraph->addNew('plotarea'); // Set gradient background $Fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'lightgrey', 'white')); $oPlotarea->setFillStyle($Fill); // Aet grid for graph $Grid =& $oPlotarea->addNew('bar_grid', null, IMAGE_GRAPH_AXIS_Y); $Grid->setFillColor('gray@0.2'); // Creat a fake object to be able to add description to second Y Axis $Dataset2 =& Image_Graph::factory('random', array(0, 0, 100)); $PlotA =& $oPlotarea->addNew('Image_Graph_Plot_Area', $Dataset2, IMAGE_GRAPH_AXIS_Y_SECONDARY); $PlotA->setTitle($strStatsArea); $AxisY =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_Y); $AxisY->forceMinimum(0.1); $AxisYsecondary =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_Y_SECONDARY); $AxisY->setTitle('Value #', 'vertical'); if ($aClickKey) { $AxisYsecondary->setTitle($this->aColumns[$aGraphFilterArray[$aClickKey]], 'vertical2'); if (count($aTempGraph) < 3) { $AxisY->setTitle($this->aColumns[$aGraphFilterArray[0]], 'vertical'); } } else { $AxisYsecondary->setTitle('Value %', 'vertical2'); } foreach ($aGraphFilterArray as $k) { $Dataset[$k] =& Image_Graph::factory('dataset'); foreach ($this->aStatsData as $key => $record) { // Split the date ($key) into days and year, and place the year on the second line $patterns = array('/(19|20)(\\d{2})-(\\d{1,2})-(\\d{1,2})/'); $replace = array('\\4-\\3--\\1\\2'); $key = preg_replace($patterns, $replace, $key); $key = preg_split('/--/', $key); if ($aFieldStyle[$k]['axis'] == 'X') { $Dataset[$k]->addPoint($key[0] . "\n" . $key[1], $record[$k], IMAGE_GRAPH_AXIS_X); } else { if ($k == 'sum_ctr') { $record[$k] *= 100; } $Dataset[$k]->addPoint($key[0] . "\n" . $key[1], $record[$k], IMAGE_GRAPH_AXIS_Y_SECONDARY); } $Dataset[$k]->setName($this->aColumns[$k]); } if ($aFieldStyle[$k]['axis'] == '1') { if ($aFieldStyle[$k]['line'] == 'Image_Graph_Plot_Bar') { $Plot[$k] =& $oPlotarea->addNew('bar', array(&$Dataset[$k])); $Plot[$k]->setFillColor($aFieldStyle[$k]['background']); $LineStyle =& Image_Graph::factory('Image_Graph_Line_Solid', $aFieldStyle[$k]['params']); $Plot[$k]->setLineStyle($LineStyle); } else { $Plot[$k] =& $oPlotarea->addNew('smooth_line', array(&$Dataset[$k])); $Plot[$k]->setFillColor($aFieldStyle[$k]['params'][0] . "@0.1"); $LineStyle =& Image_Graph::factory($aFieldStyle[$k]['line'], $aFieldStyle[$k]['params']); $Plot[$k]->setLineStyle($LineStyle); } } else { $Plot[$k] =& $oPlotarea->addNew('area', array(&$Dataset[$k]), IMAGE_GRAPH_AXIS_Y_SECONDARY); $Plot[$k]->setFillColor($aFieldStyle[$k]['background']); $LineStyle =& Image_Graph::factory('Image_Graph_Line_Solid', $aFieldStyle[$k]['params']); $Plot[$k]->setLineStyle($LineStyle); foreach ($Dataset[$k]->_data as $id => $val) { // To determine the max value of the 2nd y axis if (is_numeric($val['Y']) && (!isset($maxY2val) || $val['Y'] > $maxY2val)) { $maxY2val = $val['Y']; } } } } $maxY2val = $maxY2val + 5; $AxisYsecondary->forceMaximum($maxY2val); $oLegend =& $oPlotarea->addNew('legend'); $oLegend->setFillColor('white@0.7'); $oLegend->setFontSize(8); $oLegend->showShadow(); $AxisX =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_X); $oGraph->setPadding(10); $oGraph->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED, 'white', '#eeeeee'))); // Output the Graph $tmpGraphFile = 'cache_' . md5(microtime() . rand(1, 1000)) . '.jpg'; $oGraph->done(); return $oGraph; } }
* Main purpose: * Show line chart * * Other: * None specific * * $Id: plot_line.php,v 1.4 2005/08/03 21:21:52 nosey Exp $ * * @package Image_Graph * @author Jesper Veggerby <*****@*****.**> */ require_once 'Image/Graph.php'; // create the graph $Graph =& Image_Graph::factory('graph', array(400, 300)); // add a TrueType font $Font =& $Graph->addNew('font', 'Verdana'); // set the font size to 11 pixels $Font->setSize(10); $Graph->setFont($Font); // setup the plotarea, legend and their layout $Graph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Simple Line Chart Sample', 12)), Image_Graph::vertical($Plotarea = Image_Graph::factory('plotarea'), $Legend = Image_Graph::factory('legend'), 88), 5)); // link the legend with the plotares $Legend->setPlotarea($Plotarea); // create a random dataset for sake of simplicity $Dataset =& Image_Graph::factory('random', array(10, 2, 15, true)); // create the plot as line chart using the dataset $Plot =& $Plotarea->addNew('line', array(&$Dataset)); // set a line color $Plot->setLineColor('red'); // output the Graph $Graph->done();
* * @package Image_Graph * @author Jesper Veggerby <*****@*****.**> */ require_once 'Image/Graph.php'; // create the graph $Graph =& Image_Graph::factory('graph', array(400, 300)); // add a TrueType font $Font =& $Graph->addNew('font', 'Verdana'); // set the font size to 11 pixels $Font->setSize(10); $Graph->setFont($Font); // setup the plotarea, legend and their layout $Graph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Small Values on Log Axis Chart Sample', 12)), Image_Graph::vertical($Plotarea = Image_Graph::factory('plotarea', array('axis_log', 'axis')), $Legend = Image_Graph::factory('legend'), 88), 5)); // link the legend with the plotares $Legend->setPlotarea($Plotarea); $Dataset =& Image_Graph::factory('dataset'); $Dataset->addPoint(0.063, 5); $Dataset->addPoint(0.125, 7); $Dataset->addPoint(0.25, 8); $Dataset->addPoint(0.5, 10); $Dataset->addPoint(1, 15); $Dataset->addPoint(2, 30); $Dataset->addPoint(4, 45); $Dataset->addPoint(8, 80); // create the plot as line chart using the dataset $Plot =& $Plotarea->addNew('line', array(&$Dataset)); // set a line color $Plot->setLineColor('red'); // output the Graph $Graph->done();
* Main purpose: * Demonstrate Matrix layout * * Other: * None specific * * $Id$ * * @package Image_Graph * @author Jesper Veggerby <*****@*****.**> */ require_once 'Image/Graph.php'; // create the graph $Graph =& Image_Graph::factory('graph', array(600, 400)); // add a TrueType font $Font =& $Graph->addNew('font', 'Verdana'); // set the font size to 11 pixels $Font->setSize(7); $Graph->setFont($Font); // create the plotarea $Graph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Matrix Layout', 10)), $Matrix = Image_Graph::factory('Image_Graph_Layout_Matrix', array(3, 3)), 5)); for ($i = 0; $i < 9; $i++) { $Dataset =& Image_Graph::factory('random', array(5, 2, 15, false)); $Plotarea =& $Matrix->getEntry($i % 3, floor($i / 3)); $Plotarea->addNew('line_grid', false, IMAGE_GRAPH_AXIS_X); $Plotarea->addNew('line_grid', false, IMAGE_GRAPH_AXIS_Y); $Plot =& $Plotarea->addNew('line', $Dataset); $Plot->setLineColor('red'); $Plot->setTitle("x^2"); } $Graph->done();