/** * Method to render a statistical chart using Open Flash library. * * @return false if someting wrong */ function render() { $values = array(); foreach ($this->values as $number_variable => $variable) { $values[$number_variable] = (int) $variable; } $area = new area(); $area->set_default_dot_style(new hollow_dot()); $area->set_colour('#5B56B6'); $area->set_fill_alpha(0.4); $area->set_values($values); $area->set_key('Values', 12); $x_labels = new x_axis_labels(); $x_labels->set_steps(1); $x_labels->set_vertical(); $x_labels->set_colour('#A2ACBA'); $x_labels->set_labels($this->legend); $x = new x_axis(); $x->set_colour('#A2ACBA'); $x->set_grid_colour('#D7E4A3'); $x->set_offset(false); $x->set_steps(1); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $y = new y_axis(); $y_max = max($values) > 0 ? max($values) : 4; $y_mod = (int) ($y_max / 4 + 1); $y_max += $y_mod - $y_max % $y_mod; $y->set_range(0, $y_max, $y_mod); $y->labels = null; $y->set_offset(false); $chart = new open_flash_chart(); $chart->set_x_axis($x); $chart->add_y_axis($y); $chart->add_element($area); return $chart; }
include '../php-ofc-library/open-flash-chart.php'; $chart = new open_flash_chart(); $chart->set_title(new title('Area Chart')); // // Make our area chart: // $area = new area(); // set the circle line width: $area->set_width(2); $area->set_default_dot_style(new hollow_dot()); $area->set_colour('#838A96'); $area->set_fill_colour('#E01B49'); $area->set_fill_alpha(0.4); $area->set_values($data); // add the area object to the chart: $chart->add_element($area); $y_axis = new y_axis(); $y_axis->set_range(-2, 2, 2); $y_axis->labels = null; $y_axis->set_offset(false); $x_axis = new x_axis(); $x_axis->labels = $data; $x_axis->set_steps(2); $x_labels = new x_axis_labels(); $x_labels->set_steps(4); $x_labels->set_vertical(); // Add the X Axis Labels to the X Axis $x_axis->set_labels($x_labels); $chart->add_y_axis($y_axis); $chart->x_axis = $x_axis; echo $chart->toPrettyString();
$title = new title('Last ' . $days . ' Days Sales Chart'); $title->set_style("{font-size:14px; font-weight:bold; padding:10px;}"); $chart = new open_flash_chart(); $chart->set_title($title); $area = new area(); $area->set_colour('#5B56B6'); $area->set_values(array_values($bar_values)); $area->set_key('Products', 12); $chart->add_element($area); //define x-axis $x_labels = new x_axis_labels(); $x_labels->set_steps(4); $x_labels->set_labels($period); $x = new x_axis(); $x->set_grid_colour('#D7E4A3'); //$x->set_offset($period_offset); $x->set_steps(4); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $chart->set_x_axis($x); //define y-axis $y = new y_axis(); $range_min_value = 0; $range_max_value = max($bar_values); $y_data_step = ceil($range_max_value / $y_points); $y_data_step = $y_data_step - $y_data_step % 100; $range_max_value = ceil($range_max_value / $y_data_step) * $y_data_step; $y->set_range($range_min_value, $range_max_value, $y_data_step); $chart->add_y_axis($y); echo $chart->toPrettyString(); require_once 'confy_close.php';
protected function renderHTML() { global $g_BizSystem; $sql = "SELECT username, cflags, methods, user_agent, contact from location order by username"; $db = $g_BizSystem->GetDBConnection("Serdb"); $resultSet = $db->query($sql); if ($resultSet === false) { $err = $db->ErrorMsg(); echo $err; exit; } $chart_colors = array(); $chart_colors[0] = '#FF0000'; $chart_colors[1] = '#00FF00'; $chart_colors[2] = '#0000FF'; $chart_colors[3] = '#408080'; $chart_colors[4] = '#330000'; $chart_colors[5] = '#FDD017'; $chart_colors[6] = '#52D017'; $chart_colors[7] = '#6698FF'; $chart_colors[8] = '#00FFFF'; $chart_colors[9] = '#FF00FF'; $chart_colors[10] = '#2554C7'; $chart_colors[11] = '#806D7E'; $chart_colors[12] = '#FF8040'; $chart_colors[13] = '#C0C0C0'; $chart_colors[14] = '#808000'; $chart_colors[15] = '#800000'; $chart_colors_size = 16; $ul_contacts = array(); for ($i = 0; $i <= 5; $i++) { $ul_contacts[$i] = 0; } $prevuser = "******"; $prevcnt = 1; $ul_uas = array(); $ul_uas['asterisk'] = 0; $ul_uas['freeswitch'] = 0; $ul_uas['x-lite'] = 0; $ul_uas['eyebeam'] = 0; $ul_uas['bria'] = 0; $ul_uas['ekiga'] = 0; $ul_uas['twinkle'] = 0; $ul_uas['snom'] = 0; $ul_uas['cisco'] = 0; $ul_uas['linksys'] = 0; $ul_uas['nokia'] = 0; $ul_uas['grandstream'] = 0; $ul_uas['polycom'] = 0; $ul_uas['draytek'] = 0; $ul_uas['avm'] = 0; $ul_uas['sipura'] = 0; $ul_uas['mitel'] = 0; $ul_uas['others'] = 0; $ul_methods = array(); $ul_methods['INVITE'] = 0; $ul_methods['CANCEL'] = 0; $ul_methods['ACK'] = 0; $ul_methods['BYE'] = 0; $ul_methods['REGISTER'] = 0; $ul_methods['OPTIONS'] = 0; $ul_methods['UPDATE'] = 0; $ul_methods['PRACK'] = 0; $ul_methods['SUBSCRIBE'] = 0; $ul_methods['NOTIFY'] = 0; $ul_methods['PUBLISH'] = 0; $ul_methods['MESSAGE'] = 0; $ul_methods['INFO'] = 0; $ul_methods['REFER'] = 0; $ul_methods['OTHERS'] = 0; $ul_methods['NONE'] = 0; $ul_nat = array(); $ul_nat['NATTED'] = 0; $ul_nat['SIPPING'] = 0; $ul_proto = array(); $ul_proto['UDP'] = 0; $ul_proto['TCP'] = 0; $ul_proto['TLS'] = 0; $ul_proto['SCTP'] = 0; $yidx = 0; $ousr = 0; while ($row = $resultSet->fetch()) { $r_username = $row[0]; $r_cflags = $row[1]; $r_methods = $row[2]; $r_user_agent = $row[3]; $r_contact = $row[4]; /* statistics for contacts per user */ if ($yidx == 0) { $prevuser = $r_username; $prevcnt = 1; } else { if ($r_username == $prevuser) { $prevcnt = $prevcnt + 1; } else { $ousr++; if ($prevcnt < 5) { $ul_contacts[$prevcnt] = $ul_contacts[$prevcnt] + 1; } else { $ul_contacts[5] = $ul_contacts[5] + 1; } $prevuser = $r_username; $prevcnt = 1; } } /* known UA stats */ if (isset($r_user_agent)) { if (preg_match('/asterisk/i', $r_user_agent)) { $ul_uas['asterisk'] = $ul_uas['asterisk'] + 1; } else { if (preg_match("/freeswitch/i", $r_user_agent)) { $ul_uas['freeswitch'] = $ul_uas['freeswitch'] + 1; } else { if (preg_match("/x-lite/i", $r_user_agent)) { $ul_uas['x-lite'] = $ul_uas['x-lite'] + 1; } else { if (preg_match("/bria/i", $r_user_agent)) { $ul_uas['bria'] = $ul_uas['bria'] + 1; } else { if (preg_match("/ekiga/i", $r_user_agent)) { $ul_uas['ekiga'] = $ul_uas['ekiga'] + 1; } else { if (preg_match("/twinkle/i", $r_user_agent)) { $ul_uas['twinkle'] = $ul_uas['twinkle'] + 1; } else { if (preg_match("/snom/i", $r_user_agent)) { $ul_uas['snom'] = $ul_uas['snom'] + 1; } else { if (preg_match("/cisco/i", $r_user_agent)) { $ul_uas['cisco'] = $ul_uas['cisco'] + 1; } else { if (preg_match("/linksys/i", $r_user_agent)) { $ul_uas['linksys'] = $ul_uas['linksys'] + 1; } else { if (preg_match("/nokia/i", $r_user_agent)) { $ul_uas['nokia'] = $ul_uas['nokia'] + 1; } else { if (preg_match("/grandstream/i", $r_user_agent)) { $ul_uas['grandstream'] = $ul_uas['grandstream'] + 1; } else { if (preg_match("/polycom/i", $r_user_agent)) { $ul_uas['polycom'] = $ul_uas['polycom'] + 1; } else { if (preg_match("/draytek/i", $r_user_agent)) { $ul_uas['draytek'] = $ul_uas['draytek'] + 1; } else { if (preg_match("/avm/i", $r_user_agent)) { $ul_uas['avm'] = $ul_uas['avm'] + 1; } else { if (preg_match("/sipura/i", $r_user_agent)) { $ul_uas['sipura'] = $ul_uas['sipura'] + 1; } else { if (preg_match("/mitel/i", $r_user_agent)) { $ul_uas['mitel'] = $ul_uas['mitel'] + 1; } else { $ul_uas['others'] = $ul_uas['others'] + 1; } } } } } } } } } } } } } } } } } /* transports */ if (isset($r_contact)) { if (preg_match('/;transport=tcp/i', $r_contact)) { $ul_proto['TCP'] = $ul_proto['TCP'] + 1; } else { if (preg_match("/;transport=tls/i", $r_contact)) { $ul_proto['TLS'] = $ul_proto['TLS'] + 1; } else { if (preg_match("/;transport=sctp/i", $r_contact)) { $ul_proto['SCTP'] = $ul_proto['SCTP'] + 1; } else { $ul_proto['UDP'] = $ul_proto['UDP'] + 1; } } } } /* supported SIP methods stats */ if (isset($r_methods) && $r_methods != 0) { /* 1 - 2^0 INVITE */ if ($r_methods & 1) { $ul_methods['INVITE'] = $ul_methods['INVITE'] + 1; } /* 2 - 2^1 CANCEL */ if ($r_methods & 2) { $ul_methods['CANCEL'] = $ul_methods['CANCEL'] + 1; } /* 3 - 2^2 ACK */ if ($r_methods & 4) { $ul_methods['ACK'] = $ul_methods['ACK'] + 1; } /* 4 - 2^3 BYE */ if ($r_methods & 8) { $ul_methods['BYE'] = $ul_methods['BYE'] + 1; } /* 5 - 2^4 INFO */ if ($r_methods & 16) { $ul_methods['INFO'] = $ul_methods['INFO'] + 1; } /* 6 - 2^5 REGISTER */ if ($r_methods & 32) { $ul_methods['REGISTER'] = $ul_methods['REGISTER'] + 1; } /* 7 - 2^6 SUBSCRIBE */ if ($r_methods & 64) { $ul_methods['SUBSCRIBE'] = $ul_methods['SUBSCRIBE'] + 1; } /* 8 - 2^7 NOTIFY */ if ($r_methods & 128) { $ul_methods['NOTIFY'] = $ul_methods['NOTIFY'] + 1; } /* 9 - 2^8 MESSAGE */ if ($r_methods & 256) { $ul_methods['MESSAGE'] = $ul_methods['MESSAGE'] + 1; } /* 10 - 2^9 OPTIONS */ if ($r_methods & 512) { $ul_methods['OPTIONS'] = $ul_methods['OPTIONS'] + 1; } /* 11 - 2^10 PRACK */ if ($r_methods & 1024) { $ul_methods['PRACK'] = $ul_methods['PRACK'] + 1; } /* 12 - 2^11 UPDATE */ if ($r_methods & 2048) { $ul_methods['UPDATE'] = $ul_methods['UPDATE'] + 1; } /* 13 - 2^12 REFER */ if ($r_methods & 4096) { $ul_methods['REFER'] = $ul_methods['REFER'] + 1; } /* 14 - 2^13 PUBLISH */ if ($r_methods & 8192) { $ul_methods['PUBLISH'] = $ul_methods['PUBLISH'] + 1; } /* 15 - 2^14 OTHER */ if ($r_methods & 16384) { $ul_methods['OTHERS'] = $ul_methods['OTHERS'] + 1; } } else { $ul_methods['NONE'] = $ul_methods['NONE'] + 1; } /* supported NAT stats */ if (isset($r_cflags) && $r_cflags != 0) { if ($r_cflags & 1 << 6) { $ul_nat['NATTED'] = $ul_nat['NATTED'] + 1; } if ($r_cflags & 1 << 7) { $ul_nat['SIPPING'] = $ul_nat['SIPPING'] + 1; } } $yidx = $yidx + 1; } if ($yidx > 0) { $ousr++; if ($prevcnt < 5) { $ul_contacts[$prevcnt] = $ul_contacts[$prevcnt] + 1; } else { $ul_contacts[5] = $ul_contacts[5] + 1; } } /* user agents chart */ $ua_title = new title('User Agents'); $ua_x_labels = new x_axis_labels(); $ua_x_labels->rotate(20); $ua_bar = new bar_glass(); $chart_vals = array(); $chart_lbls = array(); $i = 0; $ymax = 10; foreach ($ul_uas as $key => $val) { if ($val > 0) { $chart_vals[$i] = new bar_value($val); $chart_vals[$i]->set_colour($chart_colors[$i % $chart_colors_size]); $chart_vals[$i]->set_tooltip($key . '<br>#val#'); $chart_lbls[$i] = $key; if ($ymax < $val) { $ymax = $val; } $i = $i + 1; } } $ua_bar->set_values($chart_vals); $ua_x_labels->set_labels($chart_lbls); $x = new x_axis(); $x->set_labels($ua_x_labels); $y = new y_axis(); $y->set_range(0, $ymax, $ymax / 10); $ul_uas_chart = new open_flash_chart(); $ul_uas_chart->set_title($ua_title); $ul_uas_chart->add_element($ua_bar); $ul_uas_chart->set_x_axis($x); $ul_uas_chart->add_y_axis($y); /* supported SIP Methods chart */ $mt_title = new title('Supported SIP Methods'); $mt_x_labels = new x_axis_labels(); $mt_x_labels->rotate(20); $mt_bar = new bar_glass(); $chart_vals = array(); $chart_lbls = array(); $i = 0; $ymax = 10; foreach ($ul_methods as $key => $val) { if ($val > 0) { $chart_vals[$i] = new bar_value($val); $chart_vals[$i]->set_colour($chart_colors[$i % $chart_colors_size]); $chart_vals[$i]->set_tooltip($key . '<br>#val#'); $chart_lbls[$i] = $key; if ($ymax < $val) { $ymax = $val; } $i = $i + 1; } } $mt_bar->set_values($chart_vals); $mt_x_labels->set_labels($chart_lbls); $x = new x_axis(); $x->set_labels($mt_x_labels); $y = new y_axis(); $y->set_range(0, $ymax, $ymax / 10); $mt_chart = new open_flash_chart(); $mt_chart->set_title($mt_title); $mt_chart->add_element($mt_bar); $mt_chart->set_x_axis($x); $mt_chart->add_y_axis($y); /* bar stacks - contacts/user, nat stats, ... */ $cn_title = new title('Contacts and NAT Stats'); $cn_x_labels = new x_axis_labels(); $cn_x_labels->rotate(20); $bar_stack = new bar_stack(); $bar_stack->set_colours($chart_colors); $chart_lbls = array(); $c = 0; $lidx = 0; $chart_vals = array(); $i = 0; $chart_vals[$i] = new bar_stack_value($yidx, $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('Records<br>#val#'); $bar_stack->append_stack($chart_vals); $chart_lbls[$lidx++] = 'All Records'; $chart_vals = array(); $i = 0; $chart_vals[$i] = new bar_stack_value($ousr, $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('Online<br>#val#'); $bar_stack->append_stack($chart_vals); $chart_lbls[$lidx++] = 'Online Users'; $chart_vals = array(); $i = 0; $chart_vals[$i] = new bar_stack_value($ul_contacts[1], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('1 contact<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($ul_contacts[2], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('2 contacts<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($ul_contacts[3], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('3 contacts<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($ul_contacts[4], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('4 contacts<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($ul_contacts[5], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('>=5 contacts <br>#val#'); $i = $i + 1; $bar_stack->append_stack($chart_vals); $chart_lbls[$lidx++] = 'Contacts per AoR'; $chart_vals = array(); $i = 0; $chart_vals[$i] = new bar_stack_value($ul_nat['NATTED'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('Natted<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($yidx - $ul_nat['NATTED'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('Not-Natted<br>#val#'); $bar_stack->append_stack($chart_vals); $chart_lbls[$lidx++] = 'Natted'; $chart_vals = array(); $i = 0; $chart_vals[$i] = new bar_stack_value($ul_nat['SIPPING'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('SIP Ping<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($yidx - $ul_nat['SIPPING'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('No SIP Ping<br>#val#'); $bar_stack->append_stack($chart_vals); $chart_lbls[$lidx++] = 'SIP Ping'; $chart_vals = array(); $i = 0; $chart_vals[$i] = new bar_stack_value($ul_proto['UDP'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('UDP<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($ul_proto['TCP'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('TCP<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($ul_proto['TLS'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('TLS<br>#val#'); $i = $i + 1; $chart_vals[$i] = new bar_stack_value($ul_proto['SCTP'], $chart_colors[$c++ % $chart_colors_size]); $chart_vals[$i]->set_tooltip('SCTP<br>#val#'); $bar_stack->append_stack($chart_vals); $chart_lbls[$lidx++] = 'Transports'; $cn_x_labels->set_labels($chart_lbls); $x = new x_axis(); $x->set_labels($cn_x_labels); $y = new y_axis(); $y->set_range(0, $yidx, $yidx / 10); $cn_chart = new open_flash_chart(); $cn_chart->set_title($cn_title); $cn_chart->add_element($bar_stack); $cn_chart->set_x_axis($x); $cn_chart->add_y_axis($y); $sHTML = ''; $sHTML .= ' <div align="center"> <p><b>Processed ' . $yidx . ' records.</b></p> </div> '; if ($yidx > 0) { $sHTML .= ' <script type="text/javascript" src="' . APP_URL . '/js/swfobject.js"></script> <script type="text/javascript"> swfobject.embedSWF( "' . APP_URL . '/modules/ser/pages/open-flash-chart.swf", "div_chart_ul_uas", "600", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_data_ul_uas"} ); swfobject.embedSWF( "' . APP_URL . '/modules/ser/pages/open-flash-chart.swf", "div_chart_ul_met", "600", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_data_ul_met"} ); swfobject.embedSWF( "' . APP_URL . '/modules/ser/pages/open-flash-chart.swf", "div_chart_ul_cns", "600", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_data_ul_cns"} ); </script> '; $sHTML .= ' <br /> <div align="center"> <div id="div_chart_ul_uas"> </div> <br /> <br /> <div id="div_chart_ul_met"> </div> <br /> <br /> <div id="div_chart_ul_cns"> </div> <br /> <br /> </div> '; $sHTML .= ' <script type="text/javascript"> function get_data_ul_uas() { data = \'' . $ul_uas_chart->toString() . '\'; return data; } function get_data_ul_met() { data = \'' . $mt_chart->toString() . '\'; return data; } function get_data_ul_cns() { data = \'' . $cn_chart->toString() . '\'; return data; } </script> '; } /* if $yidx */ return $sHTML; }
/** * Build The 3-D Bar Gharph. * * @param array $params assoc array of name/value pairs * * @return object $chart object of open flash chart. * @static */ static function &bar_3dChart(&$params) { $chart = null; if (empty($params)) { return $chart; } // $params['values'] should contains the values for each // criteria defined in $params['criteria'] $values = CRM_Utils_Array::value('values', $params); $criterias = CRM_Utils_Array::value('criteria', $params); if (!is_array($values) || empty($values) || !is_array($criterias) || empty($criterias)) { return $chart; } // get the required data. $xReferences = $xValueLabels = $xValues = $yValues = array(); foreach ($values as $xVal => $yVal) { if (!is_array($yVal) || empty($yVal)) { continue; } $xValueLabels[] = (string) $xVal; foreach ($criterias as $criteria) { $xReferences[$criteria][$xVal] = (double) CRM_Utils_Array::value($criteria, $yVal, 0); $yValues[] = (double) CRM_Utils_Array::value($criteria, $yVal, 0); } } if (empty($xReferences)) { return $chart; } // 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#"); $count = 0; foreach ($xReferences as $criteria => $values) { $toolTipVal = $tooltip; // for seperate tooltip for each criteria if (is_array($tooltip)) { $toolTipVal = CRM_Utils_Array::value($criteria, $tooltip, "{$symbol} #val#"); } // create bar_3d object $xValues[$count] = new bar_3d(); // set colour pattel $xValues[$count]->set_colour(self::$_colours[$count]); // define colur pattel with bar criterias $xValues[$count]->key((string) $criteria, 12); // define bar chart values $xValues[$count]->set_values(array_values($values)); // set tooltip $xValues[$count]->set_tooltip($toolTipVal); $count++; } $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; } // if max value of y-axis <= 0, then set default values if ($yMax <= 0) { $ySteps = 1; $yMax = 5; } else { $ySteps = $yMax / 5; } // create x axis label obj. $xLabels = new x_axis_labels(); $xLabels->set_labels($xValueLabels); // 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); foreach ($xValues as $bar) { // 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; }
/** flowview_viewchart() * * This function is taken from Slowlog. Given * a title, chart type and chart data, it will * echo the required syntax for the Callback * from the chart page to operate corectly. */ function flowview_viewchart() { global $colors, $config; include $config['base_path'] . "/plugins/flowview/lib/open-flash-chart-object.php"; include $config['base_path'] . "/plugins/flowview/lib/open-flash-chart.php"; $title = $_REQUEST["title"]; $chart_type = "bar"; $column = $_REQUEST["type"]; $sessionid = $_REQUEST["session"]; /* get the chart data from the session */ if (isset($_SESSION['flowview_flows'][$sessionid]['data'])) { $data = $_SESSION['flowview_flows'][$sessionid]['data']; } else { $filter = createfilter($sessionid); $data = $_SESSION['flowview_flows'][$sessionid]['data']; } switch ($column) { case 'flows': $unit = ucfirst($column); $suffix = "Total Flows"; $_SESSION['sess_flows_flows'] = 'on'; break; case 'bytes': $unit = ucfirst($column); $suffix = "Bytes Exchanged"; $_SESSION['sess_flows_bytes'] = 'on'; break; case 'packets': $unit = ucfirst($column); $suffix = "Packets Examined"; $_SESSION['sess_flows_packets'] = 'on'; break; } $columns = $_SESSION['flowview_flows'][$sessionid]['columns']; foreach ($columns as $key => $cdata) { if (strtolower($cdata) == $column) { $column = $key; } } if (sizeof($data)) { $elements = array(); $legend = array(); $maxvalue = 0; if (isset($_REQUEST['exclude']) && $_REQUEST['exclude'] > 0) { for ($i = 0; $i < $_REQUEST['exclude']; $i++) { array_shift($data); } } foreach ($data as $row) { if ($maxvalue < $row[$column]) { $maxvalue = $row[$column]; $scaling = flowview_autoscale($row[$column]); } } $maxvalue = flowview_getmax($maxvalue); $autorange = flowview_autoscale($maxvalue); $maxvalue = $maxvalue / $autorange[0]; $i = 0; foreach ($data as $row) { $elements[$i] = new bar_value(round($row[$column] / $autorange[0], 3)); $elements[$i]->set_colour(flowview_get_color()); $elements[$i]->set_tooltip($unit . ": #val# " . $autorange[1]); if (sizeof($row) == 4) { $legend[] = $row[0]; } else { $legend[] = $row[0] . " -\n" . $row[1]; } $i++; } $bar = new bar_glass(); $bar->set_values($elements); $title = new title($title . " (" . $suffix . ")"); $title->set_style("{font-size: 18px; color: #444444; text-align: center;}"); $x_axis_labels = new x_axis_labels(); $x_axis_labels->set_size(10); $x_axis_labels->rotate(45); $x_axis_labels->set_labels($legend); $x_axis = new x_axis(); //$x_axis->set_3d( 3 ); $x_axis->set_colours('#909090', '#909090'); $x_axis->set_labels($x_axis_labels); $y_axis = new y_axis(); $y_axis->set_offset(true); $y_axis->set_colours('#909090', '#909090'); $y_axis->set_range(0, $maxvalue, $maxvalue / 10); $y_axis->set_label_text("#val# " . $autorange[1]); $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($bar); $chart->set_x_axis($x_axis); $chart->add_y_axis($y_axis); $chart->set_bg_colour('#FEFEFE'); echo $chart->toString(); } }
public function get_jx_json_bar($info, $type = '') { $year = array_keys($info); $price = array_values($info); $chart = new open_flash_chart(); $chart->set_bg_colour('#FFFFFF'); //flash背景颜色 $x_labels = new x_axis_labels(); $x_labels->set_steps(1); $x_labels->set_size(12); $x_labels->set_colour('#000000'); if (count($year) > 0) { $x_labels->set_vertical(); } $x_labels->set_labels($year); // // 插入数据 $x = new x_axis(); $x->set_colour('#000000'); $x->set_grid_colour('#dadada'); $x->set_offset(true); $x->set_steps(1); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $x->set_offset(true); $chart->set_x_axis($x); // $bar = new bar_filled( '#74b1e0', '#9dc7e8' ); // $bar->set_values( $price ); $price_array = array(); foreach ($price as $k => $v) { $price_array[$k] = new bar_value($v); $price_array[$k]->set_colour('#74b1e0'); if ($type == 'percent') { //$y->set_label_text("#val#%"); $price_array[$k]->set_tooltip($year[$k] . '<br>' . '' . number_format($v) . '%'); } else { $price_array[$k]->set_tooltip($year[$k] . '<br>' . '' . number_format($v)); } } $bar = new bar_glass(); $bar->set_values($price_array); $chart->add_element($bar); // // LOOK: // //$x_legend = new x_legend( '1983 to 2008' ); //$x_legend->set_style( '{font-size: 20px; color: #778877}' ); //$chart->set_x_legend( $x_legend ); // // remove this when the Y Axis is smarter // $y = new y_axis(); $max = $this->get_the_right_y(max($price)); $max = $max > 0 ? $max : 1; $y->set_range(0, ($max / 5 + 1) * 5, $max / 5 + 1); // if ($max > 20 && $max <= 100) { // // $y->set_range(0, $max, 10); // }elseif($max >= 10&&$max<=20){ // $y->set_range(0, $max, 5); // } // else { // $y->set_range(0, $max); // } $y->set_colour('#000000'); $y->set_grid_colour('#dadada'); if ($type == 'percent') { $y->set_label_text(" #val#%"); } else { $y->set_label_text(" #val#"); } $chart->add_y_axis($y); $info = $chart->toPrettyString(); return $info; }
function result_screen($mode = 'reg') { global $month_names; $page_title = "Statistic Center Results"; $page_detail = " "; // ----------------------------------------- if (!checkdate($_POST['to_month'], $_POST['to_day'], $_POST['to_year'])) { die("The 'Date To:' time is incorrect, please check the input and try again"); } if (!checkdate($_POST['from_month'], $_POST['from_day'], $_POST['from_year'])) { die("The 'Date From:' time is incorrect, please check the input and try again"); } // ----------------------------------------- $to_time = mktime(12, 0, 0, $_POST['to_month'], $_POST['to_day'], $_POST['to_year']); $from_time = mktime(12, 0, 0, $_POST['from_month'], $_POST['from_day'], $_POST['from_year']); // $sql_date_to = date("Y-m-d",$to_time); // $sql_date_from = date("Y-m-d",$from_time); $human_to_date = getdate($to_time); $human_from_date = getdate($from_time); // ----------------------------------------- if ($mode == 'reg') { $table = 'Registration Statistics'; $sql_table = 'users'; $sql_field = 'added'; $page_detail = "Showing the number of users registered. (Note: All times based on GMT)"; } else { if ($mode == 'rate') { $table = 'Rating Statistics'; $sql_table = 'ratings'; $sql_field = 'added'; $page_detail = "Showing the number of ratings. (Note: All times based on GMT)"; } else { if ($mode == 'post') { $table = 'Post Statistics'; $sql_table = 'posts'; $sql_field = 'added'; $page_detail = "Showing the number of posts. (Note: All times based on GMT)"; } else { if ($mode == 'msg') { $table = 'PM Sent Statistics'; $sql_table = 'messages'; $sql_field = 'added'; $page_detail = "Showing the number of sent messages. (Note: All times based on GMT)"; } else { if ($mode == 'torr') { $table = 'Torrent Statistics'; $sql_table = 'torrents'; $sql_field = 'added'; $page_detail = "Showing the number of Torrents. (Note: All times based on GMT)"; } else { if ($mode == 'bans') { $table = 'Ban Statistics'; $sql_table = 'bans'; $sql_field = 'added'; $page_detail = "Showing the number of Bans. (Note: All times based on GMT)"; } else { if ($mode == 'comm') { $table = 'Comment Statistics'; $sql_table = 'comments'; $sql_field = 'added'; $page_detail = "Showing the number of torrent Comments. (Note: All times based on GMT)"; } else { if ($mode == 'new') { $table = 'News Statistics'; $sql_table = 'news'; $sql_field = 'added'; $page_detail = "Showing the number of News Items added. (Note: All times based on GMT)"; } else { if ($mode == 'poll') { $table = 'Poll Statistics'; $sql_table = 'polls'; $sql_field = 'added'; $page_detail = "Showing the number of Polls added. (Note: All times based on GMT)"; } else { if ($mode == 'rqst') { $table = 'Request Statistics'; $sql_table = 'requests'; $sql_field = 'added'; $page_detail = "Showing the number of Requests made. (Note: All times based on GMT)"; } } } } } } } } } } switch ($_POST['timescale']) { case 'daily': $sql_date = "%w %U %m %Y"; $php_date = "F jS - Y"; // $sql_scale = "DAY"; break; case 'monthly': $sql_date = "%m %Y"; $php_date = "F Y"; // $sql_scale = "MONTH"; break; default: // weekly $sql_date = "%U %Y"; $php_date = " [F Y]"; // $sql_scale = "WEEK"; break; } $sortby = isset($_POST['sortby']) ? mysql_real_escape_string($_POST['sortby']) : ""; // $sortby = sqlesc($sortby); $sqlq = "SELECT UNIX_TIMESTAMP(MAX({$sql_field})) as result_maxdate,\n\t\t\t\t COUNT(*) as result_count,\n\t\t\t\t DATE_FORMAT({$sql_field},'{$sql_date}') AS result_time\n\t\t\t\t FROM {$sql_table}\n\t\t\t\t WHERE UNIX_TIMESTAMP({$sql_field}) > '{$from_time}'\n\t\t\t\t AND UNIX_TIMESTAMP({$sql_field}) < '{$to_time}'\n\t\t\t\t GROUP BY result_time\n\t\t\t\t ORDER BY {$sql_field} {$sortby}"; $res = @mysql_query($sqlq); $running_total = 0; $max_result = 0; $results = array(); if (mysql_num_rows($res)) { while ($row = mysql_fetch_assoc($res)) { if ($row['result_count'] > $max_result) { $max_result = $row['result_count']; } $running_total += $row['result_count']; $results[] = array('result_maxdate' => $row['result_maxdate'], 'result_count' => $row['result_count'], 'result_time' => $row['result_time']); } include 'chart/php-ofc-library/open-flash-chart.php'; foreach ($results as $pOOp => $data) { $counts[] = (int) $data['result_count']; if ($_POST['timescale'] == 'weekly') { $labes[] = "Week #" . strftime("%W", $data['result_maxdate']) . "\n" . date($php_date, $data['result_maxdate']); } else { $labes[] = date($php_date, $data['result_maxdate']); } } $title = new title($page_title . "\n" . ucfirst($_POST['timescale']) . " " . $table . " " . $human_from_date['mday'] . " " . $month_names[$human_from_date['mon']] . " " . $human_from_date['year'] . " to " . $human_to_date['mday'] . " " . $month_names[$human_to_date['mon']] . " " . $human_to_date['year']); $chart = new open_flash_chart(); $chart->set_title($title); $line_1 = new line_hollow(); $line_1->set_values($counts); $line_1->set_key($table . " | Total: " . $running_total, 12); $line_1->set_halo_size(1); $line_1->set_width(2); $line_1->set_colour('#0099FF'); $line_1->set_dot_size(5); $chart->add_element($line_1); $x_labels = new x_axis_labels(); $x_labels->set_steps(2); $x_labels->set_vertical(); $x_labels->set_colour('#000000'); $x_labels->set_size(12); $x_labels->set_labels($labes); $x = new x_axis(); $x->set_colours('#A2ACBA', '#ECFFAF'); $x->set_steps(2); $x->set_labels($x_labels); $chart->set_x_axis($x); $y = new y_axis(); $y->set_steps(2); $y->set_colour('#A2ACBA'); $y->set_range(0, max($counts) + 5, 50); $chart->add_y_axis($y); $cont = $chart->toPrettyString(); // toFile($_SERVER["DOCUMENT_ROOT"]."/chart/","chart.json",$cont,false); // unset($cont); $html = "<script type=\"text/javascript\" src=\"chart/js/json/json2.js\"></script>"; $html .= "<script type=\"text/javascript\" src=\"chart/js/swfobject.js\"></script>"; $html .= "<script type=\"text/javascript\">\n\n\t\t\t\tfunction open_flash_chart_data()\n\t\t\t\t{\n\t\t\t\treturn JSON.stringify(data);\n\t\t\t\t}\n\n\t\t\t\tfunction findSWF(movieName) {\n\t\t\t\t if (navigator.appName.indexOf(\"Microsoft\")!= -1) {\n\t\t\t\t\treturn window[movieName];\n\t\t\t\t } else {\n\t\t\t\t\treturn document[movieName];\n\t\t\t\t }\n\t\t\t\t}\n\n\t\t\t\tvar data = " . $cont . ";\n\n\t\t\t\t\t swfobject.embedSWF(\"chart/open-flash-chart.swf\", \"my_chart\", \"800\", \"" . (max($counts) * 5 < 200 ? "250" : (max($counts) * 5 > 400 ? "400" : max($counts) * 5)) . "\", \"9.0.0\", \"expressInstall.swf\", {\"loading\":\"Please wait while the stats are loaded!\"} );\n\t\t\t\t\t </script>"; $html .= "<div id=\"my_chart\"></div>"; } else { $html .= "No results found\n"; } print $html . "<br />"; }
function netio() { function bit_to_kb($n) { return round($n / 1000, 2); } function bit_to_mb($n) { return round($n / 1000000, 2); } function get_data() { $recv_l = trim(shell_exec("cat /sys/class/net/eth0/statistics/rx_bytes")) / 8; sleep(1); $recv_n = trim(shell_exec("cat /sys/class/net/eth0/statistics/rx_bytes")) / 8; return $recv_n - $recv_l; } if (array_key_exists('netio', $_SESSION) && array_key_exists('recv_l', $_SESSION)) { if (count($_SESSION['netio']) == 10) { array_shift($_SESSION['netio']); $_SESSION['netio'][] = get_data(); } else { $_SESSION['netio'][] = get_data(); $_SESSION['recv_l'] = end($_SESSION['netio']); } } else { $_SESSION['netio'] = array(0, 0, 0, 0, 0, 0, 0, 0, 0); $_SESSION['netio'][] = get_data(); $_SESSION['recv_l'] = end($_SESSION['netio']); } $data = $_SESSION['netio']; /* $data = array(); for($i=0;$i<40;$i++){ $data[] = rand(1000000,10000000); } */ foreach (range(1, 10) as $i) { settype($i, 'string'); $second[] = $i; } if (max($data) <= 1000) { $data = array_map("bit_to_kb", $data); $y_axis_max = 1; $y_axis_key_text = " KB/s"; } elseif (max($data) <= 10000) { $data = array_map("bit_to_kb", $data); $y_axis_max = 10; $y_axis_key_text = " KB/s"; } elseif (max($data) <= 100000) { $data = array_map("bit_to_kb", $data); $y_axis_max = 100; $y_axis_key_text = " KB/s"; } elseif (max($data) <= 1000000) { $data = array_map("bit_to_kb", $data); $y_axis_max = 1000; $y_axis_key_text = " KB/s"; } elseif (max($data) <= 10000000) { $data = array_map("bit_to_mb", $data); $y_axis_max = 10; $y_axis_key_text = " MB/s"; } else { $data = array_map("bit_to_mb", $data); $y_axis_max = 100; $y_axis_key_text = " MB/s"; } $y_axis_step = $y_axis_max / 5; $chart = new open_flash_chart(); $title = new title("实时流量显示"); $title->set_style("{font-size: 12px; color: #A2ACBA; text-align: center;}"); $chart->set_title($title); #点是指曲线图上的顶点 # $d = new dot(); # $d->colour('#9C0E57')->size(3); $area = new area(); #width是指曲线的宽度 # $area->set_width(3); # $area->set_default_dot_style($d); $area->set_colour('#5B56B6'); #value即曲线顶的值 $area->set_values($data); #左上角的文字 $area->set_key($y_axis_key_text, 10); $area->set_fill_colour('#CCCAAA'); #设透明度 $area->set_fill_alpha(0.3); #area设置结束,使用add_element方法把area加进来 $chart->add_element($area); $chart->set_bg_colour('#FFFFFF'); #设置label $x_labels = new x_axis_labels(); $x_labels->set_steps(1); $x_labels->set_colour('#A2ACBA'); $x_labels->set_labels($second); #设置X轴 $x_axis = new x_axis(); $x_axis->set_colour('#A2ACBA'); $x_axis->set_grid_colour('#D7E4A3'); $x_axis->set_offset(false); $x_axis->set_steps(1); $x_axis->set_labels($x_labels); $chart->set_x_axis($x_axis); #设置X轴的文件说明,即x_legend $legend_text = "当前网络流量 " . end($data) . $y_axis_key_text; $x_legend = new x_legend($legend_text); $x_legend->set_style('{font-size: 12px; color: #778877}'); $chart->set_x_legend($x_legend); #设置轴 $y_axis = new y_axis(); $y_axis->set_range(0, $y_axis_max, $y_axis_step); $y_axis->labels = null; $y_axis->set_offset(false); $chart->add_y_axis($y_axis); header("Cache-Control: cache, must-revalidate"); header("Pragma: public"); echo $chart->toPrettyString(); }
function stacked_bar_chart($host_instance_list) { $title = new title('所有instance实际内存使用'); $title->set_style("{color: #567300; font-size: 16px; font-weight:bold;}"); $bar_stack = new bar_stack(); $bar_stack->set_colours(array('#C4D318', '#7D7B6A')); $max = 64; foreach ($host_instance_list as $i => $instance) { $jvmmem = isset($instance['jvmmem']) ? explode('/', $instance['jvmmem']) : array(); if ($jvmmem) { foreach ($jvmmem as &$j) { $j = intval($j); } $max = $max < $jvmmem[1] ? $jvmmem[1] : $max; $jvmmem[1] = $jvmmem[1] - $jvmmem[0]; } $bar_stack->append_stack($jvmmem); $lables[] = $instance['port_num']; $services[$i] = $instance['service_name']; } $bar_stack->set_keys(array(new bar_stack_key('#C4D318', 'used', 13), new bar_stack_key('#7D7B6A', 'total', 13))); $bar_stack->set_on_click('(function(x){var services=' . json_encode($services) . ';alert(services[x]);})'); //js $bar_stack->set_tooltip('#val#M,共#total#M'); $y = new y_axis(); $y->set_range(0, $max + 32, 256); $x = new x_axis(); $x->set_labels_from_array($lables); $tooltip = new tooltip(); $tooltip->set_hover(); $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($bar_stack); $chart->set_x_axis($x); $chart->add_y_axis($y); $chart->set_tooltip($tooltip); return $chart->toPrettyString(); }
function generateStats($params) { global $reportCacheLocation; // Computer Statistics Generation $dbTrackHandler = connectDb(); $resultBag = generateStatsBag($params, $dbTrackHandler); // ---------------------------------------------------- // Generate charts $animation_1 = isset($params['animation_1']) ? $params['animation_1'] : 'pop'; $delay_1 = isset($params['delay_1']) ? $params['delay_1'] : 0.5; $cascade_1 = isset($params['cascade_1']) ? $params['cascade_1'] : 1; $title = new title("Genie Report: " . $params['reportName'] . " - Generated on " . date('Y/m/d h:i:s A')); $title->set_style("{font-size: 12px; color: #000000; text-align: center;}"); $bar_stack = new bar_stack(); if ($params['reportType'] == 'computerStats') { foreach ($resultBag as $elm) { $tmpTotal = $elm[AVAIBILITY_TYPE_OFFLINE] + $elm[AVAIBILITY_TYPE_AVAILABLE] + $elm[AVAIBILITY_TYPE_BUSY]; if ($tmpTotal == 0) { $tmpTotal = 1; } // Only Chuck Norris can divide by Zero. $bar_stack->append_stack(array($elm[AVAIBILITY_TYPE_OFFLINE] / $tmpTotal * 100, $elm[AVAIBILITY_TYPE_AVAILABLE] / $tmpTotal * 100, $elm[AVAIBILITY_TYPE_BUSY] / $tmpTotal * 100)); } $bar_stack->set_colours(array('#FF0000', '#00FF00', '#A25B00')); $bar_stack->set_keys(array(new bar_stack_key('#FF0000', 'OFFLINE', 13), new bar_stack_key('#00FF00', 'FREE', 13), new bar_stack_key('#A25B00', 'BUSY', 13))); } else { $allProgNames = array(); foreach ($resultBag as $elm) { $progNames = array_keys($elm); foreach ($progNames as $progName) { if (validProgram($progName)) { if (!array_key_exists($progName, $allProgNames)) { $allProgNames[$progName] = "#" . dechex(rand(0, 10000000)); } } } } $progsArray = array(); foreach ($resultBag as $elm) { $tmpTotal = 0; $progNames = array_keys($elm); foreach ($elm as $programName => $programWeight) { if (validProgram($programName)) { $tmpTotal += $programWeight; } } //echo "<h1>$tmpTotal</h1>"; if ($tmpTotal == 0) { $tmpTotal = 1; } // Only Chuck Norris can divide by Zero. $progs = array(); foreach ($elm as $programName => $programWeight) { if (validProgram($programName)) { $percentVal = $programWeight / $tmpTotal * 100; $progs[] = new bar_stack_value($percentVal, $allProgNames[$programName]); $progsArray[$percentVal * 1000000] = $programName; } } $bar_stack->append_stack($progs); } $legends = array(); //$strAllProgNames = array_keys($allProgNames); foreach ($allProgNames as $programName => $programColor) { $legends[] = new bar_stack_key($programColor, $programName, 13); } $bar_stack->set_keys($legends); ksort($progsArray); echo "<pre>"; while (list($key, $value) = each($progsArray)) { $kw = $key / 1000000; echo "{$kw}: {$value}<br />\n"; } echo "</pre>"; } //$bar_stack->set_tooltip( 'In #x_label# you get #total# days holiday a year.<br>Number of days: #val#' ); $bar_stack->set_on_show(new bar_on_show($animation_1, $cascade_1, $delay_1)); $y = new y_axis(); $y->set_range(0, 100, 10); //$y->set_range( 0, $tmpMax, $tmpMax/10 ); $x_labels = new x_axis_labels(); $x_labels->rotate(45); $x_labels->set_labels(array_keys($resultBag)); $x = new x_axis(); $x->set_labels($x_labels); $tooltip = new tooltip(); $tooltip->set_hover(); $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($bar_stack); $chart->set_x_axis($x); $chart->add_y_axis($y); $chart->set_tooltip($tooltip); // ---------------------------------------------------- $cacheid = time(); $filename = $cacheid . '.cache.json'; $myFile = "{$reportCacheLocation}/reports-cache/" . $filename; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $chart->toPrettyString()); fclose($fh); return $cacheid; }
/** * 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 = 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. $bar->set_tooltip("{$symbol} #val#"); // 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; }
function get_linear_graph($dates, $vals, $keys = array()) { include 'php-ofc-library/open-flash-chart.php'; $max_y = 0; $arr_filled = array(); for ($i = 0; $i < count($dates); $i++) { $year[] = $dates[$i]; for ($m = 0; $m < count($vals); $m++) { $price[$m][] = (int) $vals[$m][$i]; if ($max_y < (int) $vals[$m][$i]) { $max_y = (int) $vals[$m][$i]; } if (@$arr_filled[$m] != $vals[$m][$i] and @$arr_filled[$m] == 0) { @($arr_filled[$m] = (int) $vals[$m][$i]); } } } while ($max_y % 10 != 0) { $max_y++; } $chart = new open_flash_chart(); //$title = new title( 'UK Petrol price (pence) per Litre' ); $d = new anchor(); if (count($dates) > 60) { $d->size(2); } else { $d->size(3); } $d->halo_size(1); $d->colour('#3D5C56'); $d->rotation(0); $d->sides(4); for ($i = 0; $i < count($price); $i++) { if ($arr_filled[$i] == 0) { continue; } if ($i == 0) { $color = '#5E0722'; } elseif ($i == 1) { $color = '#00FF00'; } else { $color = '#FF0000'; } $area = new area(); $area->set_colour($color); $area->set_default_dot_style($d); $area->set_values($price[$i]); if (isset($keys[$i])) { $area->set_key($keys[$i], 12); } // mb_convert_encoding($keys[$i], "UTF-8", "Windows-1251") $area->set_width(2); $chart->add_element($area); } $x_labels = new x_axis_labels(); if (count($dates) > 40) { $x_labels->set_steps(7); } else { $x_labels->set_steps(1); } $x_labels->set_vertical(); $x_labels->set_colour('#000000'); $x_labels->set_labels($year); $x_labels->rotate(-55); $x_labels->set_size(12); $x = new x_axis(); $x->set_colour('#000000'); $x->set_grid_colour('#DDDDDD'); //$x->set_offset( false ); $x->set_steps(1); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $chart->set_x_axis($x); $y = new y_axis(); $y->set_range(0, $max_y); $y->set_colour('#000000'); $y->set_grid_colour('#DDDDDD'); $chart->add_y_axis($y); $chart->set_bg_colour("#FFFFFF"); ?> <script type="text/javascript" src="script/json/json2.js"></script> <script type="text/javascript" src="script/swfobject.js"></script> <script type="text/javascript"> swfobject.embedSWF("open-flash-chart.swf", "my_chart", "600", "350", "9.0.0"); </script> <script type="text/javascript"> function ofc_ready() { } function open_flash_chart_data() { return JSON.stringify(data); } function findSWF(movieName) { if (navigator.appName.indexOf("Microsoft")!= -1) { return window[movieName]; } else { return document[movieName]; } } var data = <?php echo $chart->toPrettyString(); ?> ; </script> <?php }