/** * Build The Bar Gharph. * * @param array $params assoc array of name/value pairs * * @return object $chart object of open flash chart. * @static */ static function &barChart(&$params) { $chart = null; if (empty($params)) { return $chart; } $values = CRM_Utils_Array::value('values', $params); if (!is_array($values) || empty($values)) { return $chart; } // get the required data. $xValues = $yValues = array(); foreach ($values as $xVal => $yVal) { $yValues[] = (double) $yVal; // we has to have x values as string. $xValues[] = (string) $xVal; } $chartTitle = CRM_Utils_Array::value('legend', $params) ? $params['legend'] : ts('Bar Chart'); //set y axis parameters. $yMin = 0; // calculate max scale for graph. $yMax = ceil(max($yValues)); if ($mod = $yMax % str_pad(5, strlen($yMax) - 1, 0)) { $yMax += str_pad(5, strlen($yMax) - 1, 0) - $mod; } $ySteps = $yMax / 5; // $bar = new bar( ); // glass seem to be more cool $bar = new bar_glass(); //set values. $bar->set_values($yValues); // call user define function to handle on click event. if ($onClickFunName = CRM_Utils_Array::value('on_click_fun_name', $params)) { $bar->set_on_click($onClickFunName); } // get the currency. require_once 'CRM/Utils/Money.php'; $config = CRM_Core_Config::singleton(); $symbol = $config->defaultCurrencySymbol; // set the tooltip. $tooltip = CRM_Utils_Array::value('tip', $params, "{$symbol} #val#"); $bar->set_tooltip($tooltip); // create x axis label obj. $xLabels = new x_axis_labels(); $xLabels->set_labels($xValues); // set angle for labels. if ($xLabelAngle = CRM_Utils_Array::value('xLabelAngle', $params)) { $xLabels->rotate($xLabelAngle); } // create x axis obj. $xAxis = new x_axis(); $xAxis->set_labels($xLabels); //create y axis and set range. $yAxis = new y_axis(); $yAxis->set_range($yMin, $yMax, $ySteps); // create chart title obj. $title = new title($chartTitle); // create chart. $chart = new open_flash_chart(); // add x axis w/ labels to chart. $chart->set_x_axis($xAxis); // add y axis values to chart. $chart->add_y_axis($yAxis); // set title to chart. $chart->set_title($title); // add bar element to chart. $chart->add_element($bar); // add x axis legend. if ($xName = CRM_Utils_Array::value('xname', $params)) { $xLegend = new x_legend($xName); $xLegend->set_style("{font-size: 13px; color:#000000; font-family: Verdana; text-align: center;}"); $chart->set_x_legend($xLegend); } // add y axis legend. if ($yName = CRM_Utils_Array::value('yname', $params)) { $yLegend = new y_legend($yName); $yLegend->set_style("{font-size: 13px; color:#000000; font-family: Verdana; text-align: center;}"); $chart->set_y_legend($yLegend); } return $chart; }