/** * Generates data for OFC2 line chart in json format * * @return void */ public function get_laba_rugi() { $this->load->plugin('ofc2'); $this->load->model('jurnal_model'); $model_data = $this->jurnal_model->get_laba_rugi_data(); $bulan_data = array("Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des"); for ($i = date('n') + 1; $i <= 12; $i++) { $pendapatan_kredit = isset($model_data[$i][date('Y') - 1][4][0]) ? $model_data[$i][date('Y') - 1][4][0] : 0; $pendapatan_debit = isset($model_data[$i][date('Y') - 1][4][1]) ? $model_data[$i][date('Y') - 1][4][1] : 0; $beban_kredit = isset($model_data[$i][date('Y') - 1][5][0]) ? $model_data[$i][date('Y') - 1][5][0] : 0; $beban_debit = isset($model_data[$i][date('Y') - 1][5][1]) ? $model_data[$i][date('Y') - 1][5][1] : 0; $data[] = $pendapatan_kredit - $pendapatan_debit - ($beban_debit - $beban_kredit); $thn = date('y') - 1; $thn = strlen($thn) == 1 ? '0' . $thn : $thn; $x_data[] = $bulan_data[$i - 1] . "'" . $thn; } for ($i = 1; $i <= date('n'); $i++) { $pendapatan_kredit = isset($model_data[$i][date('Y')][4][0]) ? $model_data[$i][date('Y')][4][0] : 0; $pendapatan_debit = isset($model_data[$i][date('Y')][4][1]) ? $model_data[$i][date('Y')][4][1] : 0; $beban_kredit = isset($model_data[$i][date('Y')][5][0]) ? $model_data[$i][date('Y')][5][0] : 0; $beban_debit = isset($model_data[$i][date('Y')][5][1]) ? $model_data[$i][date('Y')][5][1] : 0; $data[] = $pendapatan_kredit - $pendapatan_debit - ($beban_debit - $beban_kredit); $x_data[] = $bulan_data[$i - 1] . "'" . date('y'); } $max = (int) max($data); $maxlen = strlen($max); $up = round($max, -($maxlen - 1)); $min = (int) min($data); $minlen = strlen($min); $down = round($min, -($minlen - 1)); $abs_max = (int) max(abs($max), abs($min)); $len = strlen($abs_max); $round = round($abs_max, -($len - 1)); $step = '1' . substr($round, 1); $up = $max > $up ? $up + $step : $up; $down = $min < $down ? $down - $step : $down; $d = new hollow_dot(); $d->size(4)->halo_size(1)->colour('#668053'); $line = new line(); $line->set_values($data); $line->set_default_dot_style($d); $line->set_width(5); $line->set_colour('#7491a0'); $x_labels = new x_axis_labels(); $x_labels->set_labels($x_data); $x = new x_axis(); $x->set_labels($x_labels); $x->set_grid_colour('#bfb8b3'); $y = new y_axis(); $y->set_grid_colour('#bfb8b3'); $y->set_range($down, $up, $step); $chart = new open_flash_chart(); $chart->add_element($line); $chart->set_x_axis($x); $chart->set_y_axis($y); $chart->set_bg_colour('#FFFFFF'); echo $chart->toPrettyString(); }
function build($options = array()) { if (empty($options)) { return false; } require_once WWW_ROOT . 'php-ofc-library/open-flash-chart.php'; $chart = new open_flash_chart(); if (isset($options['title']['txt'])) { $title = new title($options['title']['txt']); if (isset($options['title']['style'])) { $title->set_style("{" . $options['title']['style'] . "}"); } $chart->set_title($title); } if (isset($options['chart']['bg'])) { $chart->set_bg_colour($options['chart']['bg']); } if (isset($xOptions['color'])) { $x->colour($xOptions['color']); } if (isset($xOptions['grid_colour'])) { $x->grid_colour($xOptions['grid_colour']); } $col = isset($options['color']) ? $options['color'] : null; $outlineCol = isset($options['outline_col']) ? $options['outline_col'] : null; if (isset($options['charts'])) { foreach ($options['charts'] as $chartOpts) { $type = isset($chartOpts['type']) ? $chartOpts['type'] : 'bar_filled'; $diagram = new $type($chartOpts['col'], $chartOpts['outline']); if ($type == 'bar_3d') { $diagram->colour = $col; } $diagram->set_values($chartOpts['values']); if (isset($chartOpts['key'])) { $diagram->key($chartOpts['key'], 12); } $xAxis = $this->xAxis($options); if ($xAxis !== null) { $chart->set_x_axis($xAxis); } $yAxis = $this->yAxis($options); if ($xAxis !== null) { $chart->set_y_axis($yAxis); } if (isset($chartOpts['tooltip'])) { $diagram->set_tooltip($chartOpts['tooltip']); } $chart->add_element($diagram); } } return $chart->toPrettyString(); }
function get_statistic() { $this->load->library('OpenFlashChartLib', NULL, 'OFCL'); $data_1 = array(); $data_2 = array(); // generate 7 data points for ($i = 0; $i <= 7; $i++) { $x = mktime(0, 0, 0, date("m"), date("d") - $i, date('Y')); $param['sms_date'] = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") - $i, date("Y"))); $param['user_id'] = $this->session->userdata('id_user'); $y = $this->Kalkun_model->get_sms_used('date', $param); $data_1[] = new scatter_value($x, $y); $data_2[] = $y; } $def = new solid_dot(); $def->size(4)->halo_size(0)->colour('#21759B')->tooltip('#date:d M y#<br>#val# SMS'); $line = new scatter_line('#21759B', 3); $line->set_values($data_1); $line->set_default_dot_style($def); $line->set_key("SMS used in last 7 days", 10); $x = new x_axis(); // grid line and tick every 10 $x->set_range(mktime(0, 0, 0, date("m"), date("d") - 7, date('Y')), mktime(0, 0, 0, date("m"), date("d"), date('Y'))); // show ticks and grid lines for every day: $x->set_steps(86400); $labels = new x_axis_labels(); // tell the labels to render the number as a date: $labels->text('#date:M-d#'); // generate labels for every day $labels->set_steps(86400); // only display every other label (every other day) $labels->visible_steps(1); $labels->rotate(45); // finally attach the label definition to the x axis $x->set_labels($labels); $y = new y_axis(); if (max($data_2) > 0) { $max = max($data_2); } else { $max = 10; } $y->set_range(0, $max, 10); $chart = new open_flash_chart(); //$chart->set_title( $title ); $chart->add_element($line); $chart->set_x_axis($x); $chart->set_y_axis($y); echo $chart->toPrettyString(); }
/** * 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; }
function _setRankingChartdata($config) { require_once JLG_PATH_SITE . DS . "assets" . DS . "classes" . DS . "open-flash-chart" . DS . "open-flash-chart.php"; //$data = $this->get('RankChartData'); //some example data....fixme!!! $data_1 = array(); $data_2 = array(); for ($i = 0; $i < 6.2; $i += 0.2) { $data_1[] = sin($i) * 1.9 + 10; } for ($i = 0; $i < 6.2; $i += 0.2) { $data_2[] = sin($i) * 1.3 + 10; } $chart = new open_flash_chart(); //*********** //line 1 $d = new $config['dotstyle_1'](); $d->size((int) $config['line1_dot_strength']); $d->halo_size(1); $d->colour($config['line1']); $d->tooltip('Rank: #val#'); $line = new line(); $line->set_default_dot_style($d); $line->set_values($data_1); $line->set_width((int) $config['line1_strength']); ///$line->set_key($team->name, 12); $line->set_colour($config['line1']); $line->on_show(new line_on_show($config['l_animation_1'], $config['l_cascade_1'], $config['l_delay_1'])); $chart->add_element($line); //Line 2 $d = new $config['dotstyle_2'](); $d->size((int) $config['line2_dot_strength']); $d->halo_size(1); $d->colour($config['line2']); $d->tooltip('Rank: #val#'); $line = new line(); $line->set_default_dot_style($d); $line->set_values($data_2); $line->set_width((int) $config['line2_strength']); //$line->set_key($team->name, 12); $line->set_colour($config['line2']); $line->on_show(new line_on_show($config['l_animation_2'], $config['l_cascade_2'], $config['l_delay_2'])); $chart->add_element($line); //X-axis $x = new x_axis(); $x->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']); //$x->set_labels_from_array($round_labels); $chart->set_x_axis($x); $x_legend = new x_legend(JText::_('COM_JOOMLEAGUE_PRED_USER_ROUNDS')); $x_legend->set_style('{font-size: 15px; color: #778877}'); $chart->set_x_legend($x_legend); //Y-axis $y = new y_axis(); $y->set_range(0, @max($data_1) + 2, 1); $y->set_steps(round(@max($data_1) / 8)); $y->set_colours($config['y_axis_colour'], $config['y_axis_colour_inner']); $chart->set_y_axis($y); $y_legend = new y_legend(JText::_('COM_JOOMLEAGUE_PRED_USER_POINTS')); $y_legend->set_style('{font-size: 15px; color: #778877}'); $chart->set_y_legend($y_legend); $this->assignRef('rankingchartdata', $chart); }
function gsitedata() { $this->autoRender = false; $solid = $this->Session->read('sol'); $host_id = $this->Session->read('host_id'); $tinterval = 3600; $host_srch = ""; if (!empty($host_id) && $host_id != 0) { $host_srch = " AND source_id = " . $host_id; } $this->DnsMessage->recursive = -1; $site_count = $this->DnsMessage->query('SELECT hostname, COUNT(*) FROM dns_messages WHERE sol_id = ' . $solid . $host_srch . ' GROUP BY hostname ORDER BY COUNT(*) DESC LIMIT 50'); //sort($site_count); $data = array(); $x = array(); $max_resp = 0; foreach ($site_count as $site) { $data[] = array((int) $site[0]['COUNT(*)'], 0); if ($max_resp < (int) $site[0]['COUNT(*)']) { $max_resp = (int) $site[0]['COUNT(*)']; } if (empty($site[0]['hostname'])) { $x[] = (string) $site['dns_messages']['hostname']; } else { $x[] = (string) $site[0]['hostname']; } } // joson data format $title = new title(__("Host Popularity", true)); $title->set_style("{font-size: 14px; color: #990000; text-align: center; font-weight:bold;}"); $bar = new bar_stack(); $bar->set_colours(array('#e77919', '#577261')); $bar->set_on_show(new bar_on_show('grow-up', 0, 0.5)); $bar->set_values($data); $bar->set_tooltip('Host: #x_label#<br>Response #val#<br>'); $tooltip = new tooltip(); $tooltip->set_hover(); $tooltip->set_shadow(false); $tooltip->set_stroke(5); $tooltip->set_colour("#6E604F"); $tooltip->set_background_colour("#BDB396"); $data_labels = new x_axis_labels(); $data_labels->rotate(90); $data_labels->set_labels($x); $x_axis = new x_axis(); $x_axis->set_labels($data_labels); $y = new y_axis(); $y->set_range(0, $max_resp * 1.1, (int) ($max_resp / 10)); $chart = new open_flash_chart(); $chart->set_bg_colour('#F9F9F9'); $chart->set_title($title); $chart->add_element($bar); $chart->set_x_axis($x_axis); $chart->set_y_axis($y); $chart->set_tooltip($tooltip); // menu' $m = new ofc_menu("#f0E0ff", "#878787"); $m->values(array(new ofc_menu_item(__('DNS Response', true), 'go_gpage'))); $chart->set_menu($m); header("Content-Type: text/plain"); echo $chart->toPrettyString(); die; }
protected function renderHTML() { global $g_BizSystem; include_once MODULE_PATH . '/ser/config/cms.ChartsStatsAccCfg.php'; $fetchInterval = $cfg_stats_acc_fetch_interval; $sql = "SELECT method, sip_code, time, UNIX_TIMESTAMP(time) as tstamp FROM acc WHERE DATE_SUB(NOW(), INTERVAL " . $fetchInterval . " HOUR) <= time"; $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; $acc_records = array(); $acc_records['invite'] = array(); $acc_records['bye'] = array(); $acc_records['message'] = array(); $acc_records['other'] = array(); $acc_records['invite200'] = array(); $acc_records['invite404'] = array(); $acc_records['invite487'] = array(); $acc_records['inviteXYZ'] = array(); for ($i = 0; $i <= $fetchInterval; $i++) { $acc_records['invite'][$i] = 0; $acc_records['bye'][$i] = 0; $acc_records['message'][$i] = 0; $acc_records['other'][$i] = 0; $acc_records['invite200'][$i] = 0; $acc_records['invite404'][$i] = 0; $acc_records['invite487'][$i] = 0; $acc_records['inviteXYZ'][$i] = 0; } $ymax = 0; $ymin = 0xfffffff; $yidx = 0; $ousr = 0; $ctime = time(); $stime = $ctime - 3600 * $fetchInterval; while ($row = $resultSet->fetch()) { $r_method = $row[0]; $r_sip_code = $row[1]; $r_time = $row[2]; $r_tstamp = $row[3]; $idx = (int) (($r_tstamp - $stime) / 3600); /* method stats */ if (isset($r_method)) { if ($r_method == "INVITE") { $acc_records['invite'][$idx] = $acc_records['invite'][$idx] + 1; if ($r_sip_code == "200") { $acc_records['invite200'][$idx] = $acc_records['invite200'][$idx] + 1; } else { if ($r_sip_code == "404") { $acc_records['invite404'][$idx] = $acc_records['invite404'][$idx] + 1; } else { if ($r_sip_code == "487") { $acc_records['invite487'][$idx] = $acc_records['invite487'][$idx] + 1; } else { $acc_records['inviteXYZ'][$idx] = $acc_records['inviteXYZ'][$idx] + 1; } } } } else { if ($r_method == "BYE") { $acc_records['bye'][$idx] = $acc_records['bye'][$idx] + 1; } else { if ($r_method == "MESSAGE") { $acc_records['message'][$idx] = $acc_records['message'][$idx] + 1; } else { $acc_records['other'][$idx] = $acc_records['other'][$idx] + 1; } } } } $yidx = $yidx + 1; } /* sip method types chart */ $mtsobj = new open_flash_chart(); $ctitle = "SIP Method Types"; $x = new x_axis(); $xstep = (int) ($fetchInterval / 12); if ($fetchInterval % 2 != 0) { $xstep = $xstep + 1; } $x->set_steps($xstep); $time_min = $stime; $time_max = $ctime; $ctitle .= " - From " . date('Y-m-d H:i:s', $time_min); $ctitle .= " To " . date('Y-m-d H:i:s', $time_max); $time_x_labels = new x_axis_labels(); $time_x_labels->rotate(20); $chart_lbls = array(); for ($i = 0; $i < $fetchInterval; $i = $i + 1) { $chart_lbls[] = date('H:i', $stime + 3600 * $i); } $time_x_labels->visible_steps($xstep); $time_x_labels->set_labels($chart_lbls); $x->set_labels($time_x_labels); $mtsobj->set_title(new title($ctitle)); $dot_style = new dot(); $dot_style->size(3)->halo_size(1); $clr = 0; $i = 0; $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("INVITE", 10); $line[$i]->set_values($acc_records['invite']); $mtsobj->add_element($line[$i]); $i++; $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("BYE", 10); $line[$i]->set_values($acc_records['bye']); $mtsobj->add_element($line[$i]); $i++; if ($cfg_stats_acc_message) { $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("MESSAGE", 10); $line[$i]->set_values($acc_records['message']); $mtsobj->add_element($line[$i]); $i++; } if ($cfg_stats_acc_other) { $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("OTHER", 10); $line[$i]->set_values($acc_records['other']); $mtsobj->add_element($line[$i]); $i++; } $val = max($acc_records['invite']); if ($ymax < $val) { $ymax = $val; } $val = max($acc_records['bye']); if ($ymax < $val) { $ymax = $val; } if ($cfg_stats_acc_message) { $val = max($acc_records['message']); if ($ymax < $val) { $ymax = $val; } } if ($cfg_stats_acc_other) { $val = max($acc_records['other']); if ($ymax < $val) { $ymax = $val; } } $val = min($acc_records['invite']); if ($ymin > $val) { $ymin = $val; } $val = min($acc_records['bye']); if ($ymin > $val) { $ymin = $val; } if ($cfg_stats_acc_message) { $val = min($acc_records['message']); if ($ymin > $val) { $ymin = $val; } } if ($cfg_stats_acc_other) { $val = min($acc_records['other']); if ($ymin > $val) { $ymin = $val; } } if ($ymax > 10) { $y = new y_axis(); if ($ymin > 10) { $y->set_range($ymin - 10, $ymax, (int) (($ymax - $ymin + 10) / 10)); } else { $y->set_range(0, $ymax, (int) ($ymax / 10)); } $mtsobj->set_y_axis($y); } $mtsobj->set_x_axis($x); $mtsobj->set_bg_colour("#A0C0B0"); /* sip invites chart */ $ivsobj = new open_flash_chart(); $ctitle = "SIP INVITEs"; $ctitle .= " - From " . date('Y-m-d H:i:s', $time_min); $ctitle .= " To " . date('Y-m-d H:i:s', $time_max); $ivsobj->set_title(new title($ctitle)); $ymax = 0; $ymin = 0xfffffff; $i = 0; $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("200", 10); $line[$i]->set_values($acc_records['invite200']); $ivsobj->add_element($line[$i]); $i++; $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("404", 10); $line[$i]->set_values($acc_records['invite404']); $ivsobj->add_element($line[$i]); $i++; $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("487", 10); $line[$i]->set_values($acc_records['invite487']); $ivsobj->add_element($line[$i]); $i++; $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("XYZ", 10); $line[$i]->set_values($acc_records['inviteXYZ']); $ivsobj->add_element($line[$i]); $i++; $val = max($acc_records['invite200']); if ($ymax < $val) { $ymax = $val; } $val = max($acc_records['invite404']); if ($ymax < $val) { $ymax = $val; } $val = max($acc_records['invite487']); if ($ymax < $val) { $ymax = $val; } $val = max($acc_records['inviteXYZ']); if ($ymax < $val) { $ymax = $val; } $val = min($acc_records['invite200']); if ($ymin > $val) { $ymin = $val; } $val = min($acc_records['invite404']); if ($ymin > $val) { $ymin = $val; } $val = min($acc_records['invite487']); if ($ymin > $val) { $ymin = $val; } $val = min($acc_records['inviteXYZ']); if ($ymin > $val) { $ymin = $val; } if ($ymax > 10) { $y = new y_axis(); if ($ymin > 10) { $y->set_range($ymin - 10, $ymax, (int) (($ymax - $ymin + 10) / 10)); } else { $y->set_range(0, $ymax, (int) ($ymax / 10)); } $ivsobj->set_y_axis($y); } $ivsobj->set_x_axis($x); $ivsobj->set_bg_colour("#C0C0A0"); $sHTML = ''; $sHTML .= ' <div align="center"> <p><b>Processed ' . $yidx . ' records. <br />Timezone: ' . date_default_timezone_get() . ' </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_acc_methods", "600", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_data_acc_methods"} ); swfobject.embedSWF( "' . APP_URL . '/modules/ser/pages/open-flash-chart.swf", "div_chart_acc_invites", "600", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_data_acc_invites"} ); </script> '; $sHTML .= ' <br /> <div align="center"> <div id="div_chart_acc_methods"> </div> <br /> <br /> <div id="div_chart_acc_invites"> </div> <br /> <br /> </div> '; $sHTML .= ' <script type="text/javascript"> function get_data_acc_methods() { data = \'' . $mtsobj->toString() . '\'; return data; } function get_data_acc_invites() { data = \'' . $ivsobj->toString() . '\'; return data; } </script> '; } /* if $yidx */ return $sHTML; }
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; }
protected function RenderChart($oPage, $sId, $aValues, $sDrillDown = '', $aRows = array()) { // 1- Compute Open Flash Chart data // $aValueKeys = array(); $index = 0; if (count($aValues) > 0 && $sDrillDown != '') { $oFilter = DBObjectSearch::FromOQL($sDrillDown); $sClass = $oFilter->GetClass(); $sOQLClause = str_replace('SELECT ' . $sClass, '', $sDrillDown); $aSQLColNames = array_keys(current($aRows)); // Read the list of columns from the current (i.e. first) element of the array $oAppContext = new ApplicationContext(); $sURL = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search_oql&search_form=0&oql_class=' . $sClass . '&format=html&' . $oAppContext->GetForLink() . '&oql_clause='; } $aURLs = array(); foreach ($aValues as $key => $value) { // Make sure that values are integers (so that max() will work....) // and build an array of STRING with the keys (numeric keys are transformed into string by PHP :-( $aValues[$key] = (int) $value; $aValueKeys[] = (string) $key; // Build the custom query for the 'drill down' on each element if ($sDrillDown != '') { $sFilter = $sOQLClause; foreach ($aSQLColNames as $sColName) { $sFilter = str_replace(':' . $sColName, "'" . addslashes($aRows[$key][$sColName]) . "'", $sFilter); $aURLs[$index] = $sURL . urlencode($sFilter); } } $index++; } $oChart = new open_flash_chart(); if ($this->m_sType == 'bars') { $oChartElement = new bar_glass(); if (count($aValues) > 0) { $maxValue = max($aValues); } else { $maxValue = 1; } $oYAxis = new y_axis(); $aMagicValues = array(1, 2, 5, 10); $iMultiplier = 1; $index = 0; $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier; while ($maxValue > $iTop) { $index++; $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier; if ($index % count($aMagicValues) == 0) { $iMultiplier = $iMultiplier * 10; } } //echo "oYAxis->set_range(0, $iTop, $iMultiplier);\n"; $oYAxis->set_range(0, $iTop, $iMultiplier); $oChart->set_y_axis($oYAxis); $aBarValues = array(); foreach ($aValues as $iValue) { $oBarValue = new bar_value($iValue); $oBarValue->on_click("ofc_drilldown_{$sId}"); $aBarValues[] = $oBarValue; } $oChartElement->set_values($aBarValues); //$oChartElement->set_values(array_values($aValues)); $oXAxis = new x_axis(); $oXLabels = new x_axis_labels(); // set them vertical $oXLabels->set_vertical(); // set the label text $oXLabels->set_labels($aValueKeys); // Add the X Axis Labels to the X Axis $oXAxis->set_labels($oXLabels); $oChart->set_x_axis($oXAxis); } else { $oChartElement = new pie(); $oChartElement->set_start_angle(35); $oChartElement->set_animate(true); $oChartElement->set_tooltip('#label# - #val# (#percent#)'); $oChartElement->set_colours(array('#FF8A00', '#909980', '#2C2B33', '#CCC08D', '#596664')); $aData = array(); foreach ($aValues as $sValue => $iValue) { $oPieValue = new pie_value($iValue, $sValue); //@@ BUG: not passed via ajax !!! $oPieValue->on_click("ofc_drilldown_{$sId}"); $aData[] = $oPieValue; } $oChartElement->set_values($aData); $oChart->x_axis = null; } // Title given in HTML //$oTitle = new title($this->m_sTitle); //$oChart->set_title($oTitle); $oChart->set_bg_colour('#FFFFFF'); $oChart->add_element($oChartElement); $sData = $oChart->toPrettyString(); $sData = json_encode($sData); // 2- Declare the Javascript function that will render the chart data\ // $oPage->add_script(<<<EOF function ofc_get_data_{$sId}() { \treturn {$sData}; } EOF ); if (count($aURLs) > 0) { $sURLList = ''; foreach ($aURLs as $index => $sURL) { $sURLList .= "\taURLs[{$index}] = '" . addslashes($sURL) . "';\n"; } $oPage->add_script(<<<EOF function ofc_drilldown_{$sId}(index) { \tvar aURLs = new Array(); {$sURLList} \tvar sURL = aURLs[index]; \t \twindow.location.href = sURL; // Navigate ! } EOF ); } // 3- Insert the Open Flash chart // $oPage->add("<div id=\"{$sId}\"><div>\n"); $oPage->add_ready_script(<<<EOF swfobject.embedSWF(\t"../images/open-flash-chart.swf", \t"{$sId}", \t"100%", "300","9.0.0", \t"expressInstall.swf", \t{"get-data":"ofc_get_data_{$sId}", "id":"{$sId}"}, \t{'wmode': 'transparent'} ); EOF ); }
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(); }
public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = array()) { $sTitle = $this->aProperties['title']; $aDisplayValues = $this->MakeSimulatedData(); require_once APPROOT . '/pages/php-ofc-library/open-flash-chart.php'; $oChart = new open_flash_chart(); $aGroupBy = array(); $aLabels = array(); foreach ($aDisplayValues as $iRow => $aDisplayData) { $aLabels[$iRow] = $aDisplayData['label']; $aGroupBy[$iRow] = (int) $aDisplayData['count']; } $oChartElement = new bar_glass(); $aData = array(); $aChartLabels = array(); $maxValue = 0; foreach ($aGroupBy as $iRow => $iCount) { $oBarValue = new bar_value($iCount); $aData[] = $oBarValue; if ($iCount > $maxValue) { $maxValue = $iCount; } $aChartLabels[] = html_entity_decode($aLabels[$iRow], ENT_QUOTES, 'UTF-8'); } $oYAxis = new y_axis(); $aMagicValues = array(1, 2, 5, 10); $iMultiplier = 1; $index = 0; $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier; while ($maxValue > $iTop) { $index++; $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier; if ($index % count($aMagicValues) == 0) { $iMultiplier = $iMultiplier * 10; } } //echo "oYAxis->set_range(0, $iTop, $iMultiplier);\n"; $oYAxis->set_range(0, $iTop, $iMultiplier); $oChart->set_y_axis($oYAxis); $oChartElement->set_values($aData); $oXAxis = new x_axis(); $oXLabels = new x_axis_labels(); // set them vertical $oXLabels->set_vertical(); // set the label text $oXLabels->set_labels($aChartLabels); // Add the X Axis Labels to the X Axis $oXAxis->set_labels($oXLabels); $oChart->set_x_axis($oXAxis); if (!empty($sTitle)) { // The title has been given in an url, and urlencoded... // and urlencode transforms utf-8 into something similar to ISO-8859-1 // Example: é (C3A9 becomes %E9) // As a consequence, json_encode (called within open-flash-chart.php) // was returning 'null' and the graph was not displayed at all // To make sure that the graph is displayed AND to get a correct title // (at least for european characters) let's transform back into utf-8 ! $sTitle = iconv("ISO-8859-1", "UTF-8//IGNORE", $sTitle); // If the title is a dictionnary entry, fetch it $sTitle = $this->oModelReflection->DictString($sTitle); $oTitle = new title($sTitle); $oChart->set_title($oTitle); $oTitle->set_style("{font-size: 16px; font-family: Tahoma; font-weight: bold; text-align: center;}"); } $oChart->set_bg_colour('#FFFFFF'); $oChart->add_element($oChartElement); $sData = $oChart->toPrettyString(); $sData = json_encode($sData); $oPage->add_script(<<<EOF function ofc_get_data_dashlet_{$this->sId}() { \treturn {$sData}; } EOF ); $oPage->add('<div class="dashlet-content">'); $oPage->add("<div id=\"dashlet_chart_{$this->sId}\">If the chart does not display, <a href=\"http://get.adobe.com/flash/\" target=\"_blank\">install Flash</a></div>\n"); $oPage->add('</div>'); // $oPage->add_script("function ofc_resize(left, width, top, height) { /* do nothing special */ }"); $oPage->add_ready_script(<<<EOF swfobject.embedSWF(\t"../images/open-flash-chart.swf", \t"dashlet_chart_{$this->sId}", \t"100%", "300","9.0.0", \t"expressInstall.swf", \t{"get-data":"ofc_get_data_dashlet_{$this->sId}", "id":"dashlet_chart_{$this->sId}"}, \t{'wmode': 'transparent'} ); EOF ); }
function render_service_reports() { $content = "<h1>Service Reports</h1>"; // Start Filter for service type $allServiceTypes = ServiceType::get_service_types(); # $allServiceTypes = array('all' => 'all'); #$allServiceTypes = array_merge($allServiceTypes, ServiceType::get_service_types()); $allServiceTypes['all'] = 'all'; $service_type = $_GET['service_type']; $service_filter = $_GET['service_type']; if ($service_type == '' || !isset($service_type) || !is_numeric($service_type)) { $service_type = 'all'; $service_filter = ''; } $filter = "\r\n\t\t<FORM>\r\n\t\t<DIV style=\" \">\r\n\t\t<SELECT name'=service_type_report'\r\n\t\t\tonChange=\"window.location='services.php?&action=serviceReports&service_type='+this.options[this.selectedIndex].value;\">"; foreach ($allServiceTypes as $id => $name) { if ($service_type == $id) { $selected = "SELECTED"; } else { $selected = ''; } $filter .= "<OPTION value='{$id}' {$selected}>{$name}\n"; } $filter .= "\r\n\t\t</SELECT>\r\n\t\t</DIV>\r\n\t\t</FORM>\r\n\t"; // End filter $max_date = strtotime("2009-01-01"); $start_date = date("Y-m") . "-01"; // Get all months since start $workdate = strtotime($start_date); $now = strtotime("Now"); $form = new Form(auto, 3); $headings = array("Period", "In production", "Out of Production"); $data = array(); $x_ax_data = array(); $y_ax_data = array(); $handlers = array(); while ($workdate > $max_date) { $sql_enddate = date("Y-m-d", $workdate); $month_period = date("m-Y", $workdate); // This is for the chart $month_label = date("M\nY", $workdate); $graph_date = strtotime("-1 month", $workdate); $month_label = date("M\nY", $graph_date); $sql_startdate = date("Y-m-d", $workdate); array_push($x_ax_data, $month_label); array_push($y_ax_data, count(Service::get_inprod_services_at_date($sql_startdate, $service_filter))); // Add one month $workdate = strtotime("-1 month", $workdate); $sql_startdate = date("Y-m-d", $workdate); $out_of_prod = count(Service::get_outprod_services_diff_date($sql_startdate, $sql_enddate, $service_filter)); $in_prod = count(Service::get_inprod_services_diff_date($sql_startdate, $sql_enddate, $service_filter)); array_push($data, "{$sql_startdate} {$sql_enddate}"); array_push($data, $in_prod); array_push($data, $out_of_prod); array_push($handlers, "handleEvent('services.php?action=detailedServiceReports&start_date={$sql_startdate}&end_date={$sql_enddate}&service_type={$service_type}')"); } $form->setTableWidth("224px"); $form->setData($data); $form->setEventHandler($handlers); $form->setHeadings($headings); $form->setSortable(true); $content .= "<div style=\"float: left; clear: both; margin-right:28px\">" . $form->showForm() . "</div>"; // Chart // // This is the MODEL section: // include 'open-flash-chart/php-ofc-library/open-flash-chart.php'; // create an X Axis object // $y_ax_data = array_reverse($y_ax_data); $x_ax_data = array_reverse($x_ax_data); $x = new x_axis(); $x->set_steps(3); $x->set_labels_from_array($x_ax_data); $max = max($y_ax_data); $y = new y_axis(); $y->set_range(0, $max); // Bar $bar = new bar(); $bar->set_values($y_ax_data); // Bar // ------- LINE 2 ----- $line_2_default_dot = new dot(); $line_2_default_dot->size(3)->halo_size(1)->colour('#3D5C56'); $line_2 = new line(); $line_2->set_default_dot_style($line_2_default_dot); $line_2->set_values($y_ax_data); $line_2->set_width(3); $line_2->set_colour('#3D5C56'); $chart = new open_flash_chart(); $title = new title("In Production Services over Time"); $title->set_style("{font-size: 10px; font-family: Times New Roman; font-weight: bold; color: #000; text-align: center;}"); $chart->set_bg_colour('#FFFFFF'); $chart->set_title($title); $chart->add_element($bar); //$chart->add_element( $line1 ); $chart->add_element($line_2); $chart->set_x_axis($x); $chart->set_y_axis($y); // // This is the VIEW section: // Should print this first. // $heading = "\r\n\t<script type='text/javascript' src='open-flash-chart/js/json/json2.js'></script>\r\n\t<script type='text/javascript' src='open-flash-chart/js/swfobject.js'></script>\r\n\t<script type='text/javascript'>\r\n\tswfobject.embedSWF('open-flash-chart/open-flash-chart.swf', 'my_chart', '660', '350', '9.0.0');\r\n\t</script>\r\n\r\n\t<script type='text/javascript'>\r\n\r\n\tfunction open_flash_chart_data() {\r\n\t\treturn JSON.stringify(data);\r\n\t}\r\n\r\n\tfunction findSWF(movieName) {\r\n \t\tif (navigator.appName.indexOf('Microsoft')!= -1) {\r\n \t\t\treturn window[movieName];\r\n \t\t} else {\r\n \t\t\treturn document[movieName];\r\n \t\t}\r\n\t}\r\n \r\n\tvar data = " . $chart->toPrettyString() . "\r\n\r\n\t</script>\r\n\r\n\r\n\t<script type=\"text/javascript\">\r\n \r\n\tOFC = {};\r\n \r\n\tOFC.jquery = {\r\n \tname: 'jQuery',\r\n \tversion: function(src) { return \$('#'+ src)[0].get_version() },\r\n \trasterize: function (src, dst) { \$('#'+ dst).replaceWith(OFC.jquery.image(src)) },\r\n \timage: function(src) { return \"<img src='data:image/png;base64,\" + \$('#'+src)[0].get_img_binary() + \"' />\"},\r\n \tpopup: function(src) {\r\n var img_win = window.open('', 'Charts: Export as Image')\r\n with(img_win.document) {\r\n write('<html><head><title>Charts: Export as Image<\\/title><\\/head><body>' + OFC.jquery.image(src) + '<\\/body><\\/html>') }\r\n\t\t// stop the 'loading...' message\r\n\t\timg_win.document.close();\r\n \t}\r\n\t}\r\n \r\n\t// Using_ an object as namespaces is JS Best Practice. I like the Control.XXX style.\r\n\t//if (!Control) {var Control = {}}\r\n\t//if (typeof(Control == \"undefined\")) {var Control = {}}\r\n\tif (typeof(Control == \"undefined\")) {var Control = {OFC: OFC.jquery}}\r\n \r\n \r\n\t// By default, right-clicking on OFC and choosing \"save image locally\" calls this function.\r\n\t// You are free to change the code in OFC and call my wrapper (Control.OFC.your_favorite_save_method)\r\n\t// function save_image() { alert(1); Control.OFC.popup('my_chart') }\r\n\tfunction save_image() { alert(\"Your image will be displayed in a new window\"); OFC.jquery.popup('my_chart') }\r\n\t</script>\r\n\t<div id='my_chart' style='float:left; margin-left:28px;'></div>\r\n\t"; print " {$content}\n \r\n\t\t<div style=''<b>Select Service Type:</b>{$filter} <br></div>\n\r\n\t\t{$heading} "; }
function siremis_get_chart_data($groupId, $chartId, $debug = 0) { global $g_BizSystem; $cgobj = $g_BizSystem->GetService("ser.service.siremisCharts"); $cgrp = $cgobj->GetChartGroup($groupId); if ($debug == 1) { echo "Chart found {$id} :: " . $cgobj->GetChartGroupCount() . " ::: "; } $chart = $cgrp->GetChart($chartId); if (!$chart) { echo "Chart not found {$id}\n"; exit; } if ($debug == 1) { echo "Chart :: " . $cgrp->GetChartCount() . " ::: "; } $sql = "SELECT * "; $xydata = array(); // XAxis $xax = $chart->GetXAxisList(); foreach ($xax as $it) { $sql = "SELECT " . $it->GetXYData(); $xydata[0] = $it; } // YAxis $yax = $chart->GetYAxisList(); $yn = 0; foreach ($yax as $it) { $sql .= "," . $it->GetXYData(); $yn = $yn + 1; $xydata[$yn] = $it; } if ($debug == 1) { echo "::::::: {$yn} ::: " . $chart->GetYAxisCount(); } $sql .= " FROM " . $chart->GetTable(); if ($chart->GetOrderBy() && $chart->GetOrderBy() != "") { $sql .= " " . $chart->GetOrderBy(); } if ($chart->GetLimit() && $chart->GetLimit() != "") { $sql .= " " . $chart->GetLimit(); } // " ORDER BY id DESC LIMIT 30"; $db = $g_BizSystem->GetDBConnection("Serdb"); $resultSet = $db->query($sql); if ($resultSet === false) { $err = $db->ErrorMsg(); echo $err; exit; } $xdata = array(); $ydata = array(); for ($i = 0; $i < $yn; $i = $i + 1) { $ydata[$i] = array(); } $k = 0; $ymin = 0; $ymax = 0; while ($row = $resultSet->fetch()) { $xdata[$k] = $row[0]; for ($i = 0; $i < $yn; $i = $i + 1) { $ydata[$i][$k] = 0 + $row[$i + 1]; if ($k == 0) { $ymin = $ydata[$i][$k]; $ymax = $ydata[$i][$k]; } else { if ($ydata[$i][$k] < $ymin) { $ymin = $ydata[$i][$k]; } if ($ydata[$i][$k] > $ymax) { $ymax = $ydata[$i][$k]; } } } $k = $k + 1; } $ofcobj = new open_flash_chart(); $ctitle = $chart->GetTitle(); $rev = 0; if ($chart->GetOrder() && $chart->GetOrder() == "reverse") { $rev = 1; } $x = new x_axis(); $xstep = (int) ($k / 20); if ($k % 20 != 0) { $xstep = $xstep + 1; } $x->set_steps($xstep); if ($xydata[0]->getXYType() == "timestamp") { if ($rev == 1) { $time_min = $xdata[$k - 1]; $time_max = $xdata[0]; } else { $time_min = $xdata[0]; $time_max = $xdata[$k - 1]; } $ctitle .= " - From " . date('Y-m-d H:i:s', $time_min); $ctitle .= " To " . date('Y-m-d H:i:s', $time_max); $time_x_labels = new x_axis_labels(); $time_x_labels->rotate(20); $chart_lbls = array(); for ($i = 0; $i < $k; $i = $i + 1) { if ($rev == 0) { $chart_lbls[] = date('H:i', $xdata[$i]); } else { $chart_lbls[] = date('H:i', $xdata[$k - $i - 1]); } } $time_x_labels->visible_steps($xstep); $time_x_labels->set_labels($chart_lbls); $x->set_labels($time_x_labels); } else { $time_x_labels->visible_steps($xstep); if ($rev == 1) { $ctitle .= " - From " . $xdata[$k - 1] . " To " . $xdata[0]; } else { $ctitle .= " - From " . $xdata[0] . " To " . $xdata[$k - 1]; } } $ofcobj->set_title(new title($ctitle)); $dot_style = new dot(); $dot_style->size(3)->halo_size(1); for ($i = 0; $i < $yn; $i++) { if ($chart->GetChartType() == "area") { $line[$i] = new area(); $line[$i]->set_fill_alpha(0.3); $line[$i]->set_default_dot_style($dot_style); } else { if ($chart->GetChartType() == "line_dot") { $line[$i] = new line_dot(); $line[$i]->set_default_dot_style($dot_style); } else { $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); } } if ($xydata[$i + 1]->GetXYColor() && $xydata[$i + 1]->GetXYColor() != "") { $line[$i]->set_colour($xydata[$i + 1]->GetXYColor()); } if ($xydata[$i + 1]->GetXYTitle() && $xydata[$i + 1]->GetXYTitle() != "") { $line[$i]->set_key($xydata[$i + 1]->GetXYTitle(), 10); } else { $line[$i]->set_key("Key " . $i, 10); } if ($rev == 1) { $line[$i]->set_values(array_reverse($ydata[$i])); } else { $line[$i]->set_values($ydata[$i]); } $ofcobj->add_element($line[$i]); } if ($ymax > 10) { $y = new y_axis(); if ($ymin > 10) { $y->set_range($ymin - 10, $ymax, (int) (($ymax - $ymin + 10) / 10)); } else { $y->set_range(0, $ymax, (int) ($ymax / 10)); } $ofcobj->set_y_axis($y); } $ofcobj->set_x_axis($x); if ($chart->GetBGColor() && $chart->GetBGColor() != "") { $ofcobj->set_bg_colour($chart->GetBGColor()); } // return $ofcobj->toPrettyString(); return $ofcobj->toString(); }
function subscription() { acymailing::setTitle(JText::_('CHARTS'), 'stats', 'diagram&task=subscription'); $listsClass = acymailing::get('class.list'); $lists = $listsClass->getLists('listid'); $db =& JFactory::getDBO(); $db->setQuery('SELECT min(subdate) as minsubdate, min(unsubdate) as minunsubdate FROM ' . acymailing::table('listsub')); $dates = $db->loadObject(); $spaces = array(); $intervals = 10; $dates->maxsubdate = time(); $delay = ($dates->maxsubdate - $dates->minsubdate) / $intervals; for ($i = 0; $i < $intervals; $i++) { $spaces[$i] = (int) ($dates->minsubdate + $delay * $i); } $spaces[$intervals] = $dates->maxsubdate; $results = array(); $legendX = array(); for ($i = 0; $i <= $intervals; $i++) { $legendX[] = acymailing::getDate($spaces[$i]); $db->setQuery('SELECT count(subid) as total, listid FROM ' . acymailing::table('listsub') . ' WHERE `status` != 2 AND `subdate` < ' . $spaces[$i] . ' AND (`status` = 1 OR `unsubdate`>' . $spaces[$i] . ') GROUP BY listid'); $results[$i] = $db->loadObjectList('listid'); } $title = new title(JText::_('SUB_HISTORY')); $title->set_style('font-size:20px; color: #FF8040'); $lines = array(); $maxSub = 0; foreach ($lists as $listid => $oneList) { $lines[$listid] = new line_base(); $values = array(); for ($i = 0; $i <= $intervals; $i++) { $values[] = empty($results[$i][$listid]->total) ? 0 : (int) $results[$i][$listid]->total; } $lines[$listid]->set_values($values); $lines[$listid]->set_text($oneList->name); $lines[$listid]->set_colour($oneList->color); $maxSub = max($maxSub, max($values)); } $x_axis = new x_axis(); $xlabelobject = new x_axis_labels(); $xlabelobject->rotate(-20); $xlabelobject->set_labels($legendX); $x_axis->set_labels($xlabelobject); $y_axis = new y_axis(); $y_axis->range(0, $maxSub, intval($maxSub / 10)); $chart = new open_flash_chart(); $chart->set_x_axis($x_axis); $chart->set_y_axis($y_axis); $chart->set_title($title); foreach ($lines as $oneLine) { $chart->add_element($oneLine); } $this->assignRef('chart', $chart); }
private static function make_bandwidth_chart($values, $options = array()) { if (!$values || !count($values)) { return false; } $title = !empty($options['title']) ? $options['title'] : 'Chart'; //array_check_value($options, 'title', 'BI Chart'); $step = !empty($options['step']) ? $options['step'] : 0.75; //array_check_value($options, 'step', 0.75); $max = !empty($options['max']) ? $options['max'] : 0; //array_check_value($options, 'max', 0); $value_mod = !empty($options['value_modifier']) ? $options['value_modifier'] : 1; //array_check_value($options, 'value_modifier', 1); $input_title = !empty($options['input_title']) ? $options['input_title'] : 'Downloads for :key: #val#'; //array_check_value($options, 'input_title', 'Downloads for :key: #val#'); $output_title = !empty($options['output_title']) ? $options['output_title'] : 'Uploads for :key: #val#'; //array_check_value($options, 'output_title', 'Uploads for :key: #val#'); $total_title = !empty($options['total_title']) ? $options['total_title'] : 'Total for :key: #val#'; //array_check_value($options, 'total_title', 'Total for :key: #val#'); $on_click = !empty($options['on_click']) ? $options['on_click'] : false; //array_check_value($options, 'on_click', false); $x_labels = !empty($options['x_labels']) ? $options['x_labels'] : array_keys($values); //array_check_value($options, 'x_labels', array_keys($values)); include_once APP_FOLDER . '/libraries/php-ofc-library/ofc_title.php'; include_once APP_FOLDER . '/libraries/php-ofc-library/open-flash-chart.php'; //include(APP_FOLDER . '/libraries/php-ofc-library/ofc_bar_glass_value.php'); include_once APP_FOLDER . '/libraries/php-ofc-library/ofc_line_dot.php'; include_once APP_FOLDER . '/libraries/php-ofc-library/ofc_line_base.php'; include_once APP_FOLDER . '/libraries/php-ofc-library/ofc_x_axis.php'; $title = new title($title); $chart = new open_flash_chart(); $chart->set_title($title); $input = array(); $ouput = array(); $total = array(); $clicks = array(); foreach ($values as $key => $value) { $this_value = (double) number_format($value['input'] / $value_mod, 2, '.', ''); $tmp = new bar_glass_value($this_value); $tmp->set_tooltip(preg_replace('/:key/', $key, $input_title)); $input[] = $tmp; $this_value = (double) number_format($value['output'] / $value_mod, 2, '.', ''); $tmp = new bar_glass_value($this_value); $tmp->set_tooltip(preg_replace('/:key/', $key, $output_title)); $output[] = $tmp; $this_value = (double) number_format(($value['input'] + $value['output']) / $value_mod, 2, '.', ''); $tmp = new dot_value($this_value, '#000066'); $tmp->set_tooltip(preg_replace('/:key/', $key, $total_title)); $total[] = $tmp; if ($on_click) { $tmp = (double) number_format(($value['input'] + $value['output']) / $value_mod, 2, '.', ''); $clicks[] = $tmp; } $max = ceil(max(($value['input'] + $value['output']) / $value_mod, $max)); } $x_axis = new x_axis(); $x_axis->set_labels_from_array($x_labels); $x_axis->set_3d(5); $x_axis->colour = '#909090'; if ($max > 0) { //Don't know why we sometimes get a division by zero error @($max = $max + ($step - $max % $step)); } if ($max / $step > 5) { $step = floor($max / 5); } else { if ($max / $step <= 1) { $step = floor($max / 2); } } $y_axis = new y_axis(); $y_axis->set_range(0, $max, $step); $input_bar = new bar_glass(); $input_bar->set_values($input); $input_bar->colour = '#D54C78'; $output_bar = new bar_glass(); $output_bar->set_values($output); $output_bar->colour = '#78D54C'; $total_graph = new line_hollow(); $total_graph->set_colour('#9999FF'); $total_graph->set_values($total); if ($on_click) { $click_graph = new line(); $click_graph->set_values($clicks); $click_graph->set_on_click($on_click); $chart->add_element($click_graph); } $chart->set_x_axis($x_axis); $chart->set_y_axis($y_axis); $chart->add_element($input_bar); $chart->add_element($output_bar); $chart->add_element($total_graph); //$decoded = json_decode($chart->toString()); return $chart->toString(); }
function get_daily_entries($form, $colors = false, $type = "DATE") { global $wpdb, $frmdb; if (!$colors) { $colors = array('#EF8C08', '#21759B', '#1C9E05'); } $type = strtoupper($type); //Chart for Entries Submitted $values = array(); $labels = array(); if ($type == 'HOUR') { $start_timestamp = strtotime('-48 hours'); } else { if ($type == 'MONTH') { $start_timestamp = strtotime('-1 year'); } else { if ($type == 'YEAR') { $start_timestamp = strtotime('-10 years'); } else { $start_timestamp = strtotime('-1 month'); } } } $end_timestamp = time(); if ($type == 'HOUR') { $query = "SELECT en.created_at as endate,COUNT(*) as encount FROM {$frmdb->entries} en WHERE en.created_at >= '" . date("Y-n-j H", $start_timestamp) . ":00:00' AND en.form_id={$form->id} GROUP BY endate"; } else { $query = "SELECT DATE(en.created_at) as endate,COUNT(*) as encount FROM {$frmdb->entries} en WHERE en.created_at >= '" . date("Y-n-j", $start_timestamp) . " 00:00:00' AND en.form_id={$form->id} GROUP BY {$type}(en.created_at)"; } $entries_array = $wpdb->get_results($query); $temp_array = $counts_array = $dates_array = array(); // Refactor Array for use later on foreach ($entries_array as $e) { $e_key = $e->endate; if ($type == 'HOUR') { $e_key = date('Y-m-d H', strtotime($e->endate)) . ':00:00'; } else { if ($type == 'MONTH') { $e_key = date('Y-m', strtotime($e->endate)) . '-01'; } else { if ($type == 'YEAR') { $e_key = date('Y', strtotime($e->endate)) . '-01-01'; } } } $temp_array[$e_key] = $e->encount; } // Get the dates array if ($type == 'HOUR') { for ($e = $start_timestamp; $e <= $end_timestamp; $e += 60 * 60) { if (!in_array(date('Y-m-d H', $e) . ':00:00', $dates_array)) { $dates_array[] = date('Y-m-d H', $e) . ':00:00'; } } $date_format = get_option('time_format'); } else { if ($type == 'MONTH') { for ($e = $start_timestamp; $e <= $end_timestamp; $e += 60 * 60 * 24 * 25) { if (!in_array(date('Y-m', $e) . '-01', $dates_array)) { $dates_array[] = date('Y-m', $e) . '-01'; } } $date_format = 'F Y'; } else { if ($type == 'YEAR') { for ($e = $start_timestamp; $e <= $end_timestamp; $e += 60 * 60 * 24 * 364) { if (!in_array(date('Y', $e) . '-01-01', $dates_array)) { $dates_array[] = date('Y', $e) . '-01-01'; } } $date_format = 'Y'; } else { for ($e = $start_timestamp; $e <= $end_timestamp; $e += 60 * 60 * 24) { $dates_array[] = date("Y-m-d", $e); } $date_format = get_option('date_format'); } } } // Make sure counts array is in order and includes zero click days foreach ($dates_array as $date_str) { if (isset($temp_array[$date_str])) { $counts_array[$date_str] = $temp_array[$date_str]; } else { $counts_array[$date_str] = 0; } } foreach ($counts_array as $date => $count) { $labels[] = date_i18n($date_format, strtotime($date)); $values[] = (int) $count; } if ($type == 'MONTH') { $title = __('Monthly Entries', 'formidable'); } else { if ($type == 'YEAR') { $title = __('Yearly Entries', 'formidable'); } else { if ($type == 'HOUR') { $title = __('Hourly Entries', 'formidable'); } else { $title = __('Daily Entries', 'formidable'); } } } $title = new title($title); $line_1_default_dot = new dot(); $line_1_default_dot->colour($colors[0]); $line_1_default_dot->tooltip('#x_label#<br>#val# Entries'); $line_1 = new line(); $line_1->set_default_dot_style($line_1_default_dot); $line_1->set_values($values); $line_1->set_colour($colors[1]); $chart = new open_flash_chart(); $chart->set_title($title); $chart->set_bg_colour('#FFFFFF'); $x = new x_axis(); $x_labels = new x_axis_labels(); $x_labels->rotate(340); $x_labels->set_labels($labels); if (count($labels) > 15) { $x_labels->visible_steps(2); } $x->set_labels($x_labels); $chart->set_x_axis($x); $y = new y_axis(); if (!empty($values)) { $max = max($values) + 1; $step = ceil($max / 10); $y->set_range(0, $max, $step); } $chart->add_element($line_1); $chart->set_y_axis($y); return $chart->toPrettyString(); }
function _setChartdata($config) { require_once JLG_PATH_SITE . '/assets/classes/open-flash-chart/open-flash-chart.php'; $data = $this->get('ChartData'); // Calculate Values for Chart Object $forSum = array(); $againstSum = array(); $matchDayGoalsCount = array(); $round_labels = array(); foreach ($data as $rw) { if (!$rw->homegoalspd) { $rw->homegoalspd = 0; } if (!$rw->guestgoalspd) { $rw->guestgoalspd = 0; } $homeSum[] = (int) $rw->homegoalspd; $awaySum[] = (int) $rw->guestgoalspd; // check, if both results are missing and avoid drawing the flatline of "0" goals for not played games yet if (!$rw->homegoalspd && !$rw->guestgoalspd) { $matchDayGoalsCount[] = null; } else { $matchDayGoalsCount[] = (int) $rw->homegoalspd + $rw->guestgoalspd; } $round_labels[] = $rw->roundcode; } $chart = new open_flash_chart(); //$chart->set_title( $title ); $chart->set_bg_colour($config['bg_colour']); if (!empty($homeSum) && !empty($awaySum)) { if ($config['home_away_stats']) { $bar1 = new $config['bartype_1'](); $bar1->set_values($homeSum); $bar1->set_tooltip(JText::_('COM_JOOMLEAGUE_STATS_HOME') . ": #val#"); $bar1->set_colour($config['bar1']); $bar1->set_on_show(new bar_on_show($config['animation_1'], $config['cascade_1'], $config['delay_1'])); $bar1->set_key(JText::_('COM_JOOMLEAGUE_STATS_HOME'), 12); $bar2 = new $config['bartype_2'](); $bar2->set_values($awaySum); $bar2->set_tooltip(JText::_('COM_JOOMLEAGUE_STATS_AWAY') . ": #val#"); $bar2->set_colour($config['bar2']); $bar2->set_on_show(new bar_on_show($config['animation_2'], $config['cascade_2'], $config['delay_2'])); $bar2->set_key(JText::_('COM_JOOMLEAGUE_STATS_AWAY'), 12); $chart->add_element($bar1); $chart->add_element($bar2); } } // total $d = new $config['dotstyle_3'](); $d->size((int) $config['line3_dot_strength']); $d->halo_size(1); $d->colour($config['line3']); $d->tooltip(JText::_('COM_JOOMLEAGUE_STATS_TOTAL2') . ' #val#'); $line = new line(); $line->set_default_dot_style($d); $line->set_values($matchDayGoalsCount); $line->set_width((int) $config['line3_strength']); $line->set_key(JText::_('COM_JOOMLEAGUE_STATS_TOTAL'), 12); $line->set_colour($config['line3']); $line->on_show(new line_on_show($config['l_animation_3'], $config['l_cascade_3'], $config['l_delay_3'])); $chart->add_element($line); $x = new x_axis(); $x->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']); $x->set_labels_from_array($round_labels); $chart->set_x_axis($x); $x_legend = new x_legend(JText::_('COM_JOOMLEAGUE_STATS_ROUNDS')); $x_legend->set_style('{font-size: 15px; color: #778877}'); $chart->set_x_legend($x_legend); $y = new y_axis(); $y->set_range(0, @max($matchDayGoalsCount) + 2, 1); $y->set_steps(round(@max($matchDayGoalsCount) / 8)); $y->set_colours($config['y_axis_colour'], $config['y_axis_colour_inner']); $chart->set_y_axis($y); $y_legend = new y_legend(JText::_('COM_JOOMLEAGUE_STATS_GOALS')); $y_legend->set_style('{font-size: 15px; color: #778877}'); $chart->set_y_legend($y_legend); $this->chartdata = $chart; }
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; }
$labels2 = new x_axis_labels(); $labels2->set_labels($tab_libelles2); $labels2->rotate(270); // Absisses $x2 = new x_axis(); //$x->set_labels( $x_labels ); $x2->set_stroke(2); $x2->set_tick_height(2); $x2->set_colour("#d000d0"); $x2->set_labels($labels2); // Tooltip du graphe ! $chart2->set_tooltip($t); $title2 = new title("Evolution par joueur"); $chart2->set_title($title2); $chart2->set_y_axis($y2); $chart2->set_x_axis($x2); $fp = fopen($fichierImage, "w"); // ouverture du fichier en écriture fputs($fp, $chart2->toPrettyString()); // on écrit les données fclose($fp); } echo "<div id=\"my_chart2\"> </div>"; ferme_base($db_link); } ?> <script type="text/javascript" src="js/swfobject.js"></script>
/** 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 GetRenderContent(WebPage $oPage, $aExtraParams = array(), $sId) { $sHtml = ''; // Add the extra params into the filter if they make sense for such a filter $bDoSearch = utils::ReadParam('dosearch', false); if ($this->m_oSet == null) { $aQueryParams = array(); if (isset($aExtraParams['query_params'])) { $aQueryParams = $aExtraParams['query_params']; } if ($this->m_sStyle != 'links') { $oAppContext = new ApplicationContext(); $sClass = $this->m_oFilter->GetClass(); $aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($sClass)); $aCallSpec = array($sClass, 'MapContextParam'); if (is_callable($aCallSpec)) { foreach ($oAppContext->GetNames() as $sContextParam) { $sParamCode = call_user_func($aCallSpec, $sContextParam); //Map context parameter to the value/filter code depending on the class if (!is_null($sParamCode)) { $sParamValue = $oAppContext->GetCurrentValue($sContextParam, null); if (!is_null($sParamValue)) { $aExtraParams[$sParamCode] = $sParamValue; } } } } foreach ($aFilterCodes as $sFilterCode) { $externalFilterValue = utils::ReadParam($sFilterCode, '', false, 'raw_data'); $condition = null; if (isset($aExtraParams[$sFilterCode])) { $condition = $aExtraParams[$sFilterCode]; } if ($bDoSearch && $externalFilterValue != "") { // Search takes precedence over context params... unset($aExtraParams[$sFilterCode]); if (!is_array($externalFilterValue)) { $condition = trim($externalFilterValue); } else { if (count($externalFilterValue) == 1) { $condition = trim($externalFilterValue[0]); } else { $condition = $externalFilterValue; } } } if (!is_null($condition)) { $sOpCode = null; // default operator if (is_array($condition)) { // Multiple values, add them as AND X IN (v1, v2, v3...) $sOpCode = 'IN'; } $this->AddCondition($sFilterCode, $condition, $sOpCode); } } if ($bDoSearch) { // Keep the table_id identifying this table if we're performing a search $sTableId = utils::ReadParam('_table_id_', null, false, 'raw_data'); if ($sTableId != null) { $aExtraParams['table_id'] = $sTableId; } } } $aOrderBy = array(); if (isset($aExtraParams['order_by'])) { // Convert the string describing the order_by parameter into an array // The syntax is +attCode1,-attCode2 // attCode1 => ascending, attCode2 => descending $aTemp = explode(',', $aExtraParams['order_by']); foreach ($aTemp as $sTemp) { $aMatches = array(); if (preg_match('/^([+-])?(.+)$/', $sTemp, $aMatches)) { $bAscending = true; if ($aMatches[1] == '-') { $bAscending = false; } $aOrderBy[$aMatches[2]] = $bAscending; } } } $this->m_oSet = new CMDBObjectSet($this->m_oFilter, $aOrderBy, $aQueryParams); } switch ($this->m_sStyle) { case 'count': if (isset($aExtraParams['group_by'])) { if (isset($aExtraParams['group_by_label'])) { $oGroupByExp = Expression::FromOQL($aExtraParams['group_by']); $sGroupByLabel = $aExtraParams['group_by_label']; } else { // Backward compatibility: group_by is simply a field id $sAlias = $this->m_oFilter->GetClassAlias(); $oGroupByExp = new FieldExpression($aExtraParams['group_by'], $sAlias); $sGroupByLabel = MetaModel::GetLabel($this->m_oFilter->GetClass(), $aExtraParams['group_by']); } $aGroupBy = array(); $aGroupBy['grouped_by_1'] = $oGroupByExp; $sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy, true); $aRes = CMDBSource::QueryToArray($sSql); $aGroupBy = array(); $aLabels = array(); $aValues = array(); $iTotalCount = 0; foreach ($aRes as $iRow => $aRow) { $sValue = $aRow['grouped_by_1']; $aValues[$iRow] = $sValue; $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue); $aLabels[$iRow] = $sHtmlValue; $aGroupBy[$iRow] = (int) $aRow['_itop_count_']; $iTotalCount += $aRow['_itop_count_']; } $aData = array(); $oAppContext = new ApplicationContext(); $sParams = $oAppContext->GetForLink(); foreach ($aGroupBy as $iRow => $iCount) { // Build the search for this subset $oSubsetSearch = $this->m_oFilter->DeepClone(); $oCondition = new BinaryExpression($oGroupByExp, '=', new ScalarExpression($aValues[$iRow])); $oSubsetSearch->AddConditionExpression($oCondition); $sFilter = urlencode($oSubsetSearch->serialize()); $aData[] = array('group' => $aLabels[$iRow], 'value' => "<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=search&dosearch=1&{$sParams}&filter={$sFilter}\">{$iCount}</a>"); // TO DO: add the context information } $aAttribs = array('group' => array('label' => $sGroupByLabel, 'description' => ''), 'value' => array('label' => Dict::S('UI:GroupBy:Count'), 'description' => Dict::S('UI:GroupBy:Count+'))); $sFormat = isset($aExtraParams['format']) ? $aExtraParams['format'] : 'UI:Pagination:HeaderNoSelection'; $sHtml .= $oPage->GetP(Dict::Format($sFormat, $iTotalCount)); $sHtml .= $oPage->GetTable($aAttribs, $aData); } else { // Simply count the number of elements in the set $iCount = $this->m_oSet->Count(); $sFormat = 'UI:CountOfObjects'; if (isset($aExtraParams['format'])) { $sFormat = $aExtraParams['format']; } $sHtml .= $oPage->GetP(Dict::Format($sFormat, $iCount)); } break; case 'join': $aDisplayAliases = isset($aExtraParams['display_aliases']) ? explode(',', $aExtraParams['display_aliases']) : array(); if (!isset($aExtraParams['group_by'])) { $sHtml .= $oPage->GetP(Dict::S('UI:Error:MandatoryTemplateParameter_group_by')); } else { $aGroupByFields = array(); $aGroupBy = explode(',', $aExtraParams['group_by']); foreach ($aGroupBy as $sGroupBy) { $aMatches = array(); if (preg_match('/^(.+)\\.(.+)$/', $sGroupBy, $aMatches) > 0) { $aGroupByFields[] = array('alias' => $aMatches[1], 'att_code' => $aMatches[2]); } } if (count($aGroupByFields) == 0) { $sHtml .= $oPage->GetP(Dict::Format('UI:Error:InvalidGroupByFields', $aExtraParams['group_by'])); } else { $aResults = array(); $aCriteria = array(); while ($aObjects = $this->m_oSet->FetchAssoc()) { $aKeys = array(); foreach ($aGroupByFields as $aField) { $sAlias = $aField['alias']; if (is_null($aObjects[$sAlias])) { $aKeys[$sAlias . '.' . $aField['att_code']] = ''; } else { $aKeys[$sAlias . '.' . $aField['att_code']] = $aObjects[$sAlias]->Get($aField['att_code']); } } $sCategory = implode($aKeys, ' '); $aResults[$sCategory][] = $aObjects; $aCriteria[$sCategory] = $aKeys; } $sHtml .= "<table>\n"; // Construct a new (parametric) query that will return the content of this block $oBlockFilter = $this->m_oFilter->DeepClone(); $aExpressions = array(); $index = 0; foreach ($aGroupByFields as $aField) { $aExpressions[] = '`' . $aField['alias'] . '`.`' . $aField['att_code'] . '` = :param' . $index++; } $sExpression = implode(' AND ', $aExpressions); $oExpression = Expression::FromOQL($sExpression); $oBlockFilter->AddConditionExpression($oExpression); $aExtraParams['menu'] = false; foreach ($aResults as $sCategory => $aObjects) { $sHtml .= "<tr><td><h1>{$sCategory}</h1></td></tr>\n"; if (count($aDisplayAliases) == 1) { $aSimpleArray = array(); foreach ($aObjects as $aRow) { $oObj = $aRow[$aDisplayAliases[0]]; if (!is_null($oObj)) { $aSimpleArray[] = $oObj; } } $oSet = CMDBObjectSet::FromArray($this->m_oFilter->GetClass(), $aSimpleArray); $sHtml .= "<tr><td>" . cmdbAbstractObject::GetDisplaySet($oPage, $oSet, $aExtraParams) . "</td></tr>\n"; } else { $index = 0; $aArgs = array(); foreach ($aGroupByFields as $aField) { $aArgs['param' . $index] = $aCriteria[$sCategory][$aField['alias'] . '.' . $aField['att_code']]; $index++; } $oSet = new CMDBObjectSet($oBlockFilter, array(), $aArgs); $sHtml .= "<tr><td>" . cmdbAbstractObject::GetDisplayExtendedSet($oPage, $oSet, $aExtraParams) . "</td></tr>\n"; } } $sHtml .= "</table>\n"; } } break; case 'list': $aClasses = $this->m_oSet->GetSelectedClasses(); $aAuthorizedClasses = array(); if (count($aClasses) > 1) { // Check the classes that can be read (i.e authorized) by this user... foreach ($aClasses as $sAlias => $sClassName) { if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $this->m_oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS)) { $aAuthorizedClasses[$sAlias] = $sClassName; } } if (count($aAuthorizedClasses) > 0) { if ($this->m_oSet->Count() > 0) { $sHtml .= cmdbAbstractObject::GetDisplayExtendedSet($oPage, $this->m_oSet, $aExtraParams); } else { // Empty set $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay')); } } else { // Not authorized $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay')); } } else { // The list is made of only 1 class of objects, actions on the list are possible if ($this->m_oSet->Count() > 0 && UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_READ, $this->m_oSet) == UR_ALLOWED_YES) { $sHtml .= cmdbAbstractObject::GetDisplaySet($oPage, $this->m_oSet, $aExtraParams); } else { $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay')); $sClass = $this->m_oFilter->GetClass(); $bDisplayMenu = isset($aExtraParams['menu']) ? $aExtraParams['menu'] == true : true; if ($bDisplayMenu) { if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES) { $sLinkTarget = ''; $oAppContext = new ApplicationContext(); $sParams = $oAppContext->GetForLink(); // 1:n links, populate the target object as a default value when creating a new linked object if (isset($aExtraParams['target_attr'])) { $sLinkTarget = ' target="_blank" '; $aExtraParams['default'][$aExtraParams['target_attr']] = $aExtraParams['object_id']; } $sDefault = ''; if (!empty($aExtraParams['default'])) { foreach ($aExtraParams['default'] as $sKey => $sValue) { $sDefault .= "&default[{$sKey}]={$sValue}"; } } $sHtml .= $oPage->GetP("<a{$sLinkTarget} href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=new&class={$sClass}&{$sParams}{$sDefault}\">" . Dict::Format('UI:ClickToCreateNew', Metamodel::GetName($sClass)) . "</a>\n"); } } } } break; case 'links': //$bDashboardMode = isset($aExtraParams['dashboard']) ? ($aExtraParams['dashboard'] == 'true') : false; //$bSelectMode = isset($aExtraParams['select']) ? ($aExtraParams['select'] == 'true') : false; if ($this->m_oSet->Count() > 0 && UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_READ, $this->m_oSet) == UR_ALLOWED_YES) { //$sLinkage = isset($aExtraParams['linkage']) ? $aExtraParams['linkage'] : ''; $sHtml .= cmdbAbstractObject::GetDisplaySet($oPage, $this->m_oSet, $aExtraParams); } else { $sClass = $this->m_oFilter->GetClass(); $oAttDef = MetaModel::GetAttributeDef($sClass, $this->m_aParams['target_attr']); $sTargetClass = $oAttDef->GetTargetClass(); $sHtml .= $oPage->GetP(Dict::Format('UI:NoObject_Class_ToDisplay', MetaModel::GetName($sTargetClass))); $bDisplayMenu = isset($this->m_aParams['menu']) ? $this->m_aParams['menu'] == true : true; if ($bDisplayMenu) { if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES) { $oAppContext = new ApplicationContext(); $sParams = $oAppContext->GetForLink(); $sDefaults = ''; if (isset($this->m_aParams['default'])) { foreach ($this->m_aParams['default'] as $sName => $sValue) { $sDefaults .= '&' . urlencode($sName) . '=' . urlencode($sValue); } } $sHtml .= $oPage->GetP("<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=modify_links&class={$sClass}&sParams&link_attr=" . $aExtraParams['link_attr'] . "&id=" . $aExtraParams['object_id'] . "&target_class={$sTargetClass}&addObjects=true{$sDefaults}\">" . Dict::Format('UI:ClickToCreateNew', Metamodel::GetName($sClass)) . "</a>\n"); } } } break; case 'details': while ($oObj = $this->m_oSet->Fetch()) { $sHtml .= $oObj->GetDetails($oPage); // Still used ??? } break; case 'actions': $sClass = $this->m_oFilter->GetClass(); $oAppContext = new ApplicationContext(); $bContextFilter = isset($aExtraParams['context_filter']) ? isset($aExtraParams['context_filter']) != 0 : false; if ($bContextFilter) { $aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($this->m_oFilter->GetClass())); foreach ($oAppContext->GetNames() as $sFilterCode) { $sContextParamValue = $oAppContext->GetCurrentValue($sFilterCode, null); if (!is_null($sContextParamValue) && !empty($sContextParamValue) && MetaModel::IsValidFilterCode($sClass, $sFilterCode)) { $this->AddCondition($sFilterCode, $sContextParamValue); } } $aQueryParams = array(); if (isset($aExtraParams['query_params'])) { $aQueryParams = $aExtraParams['query_params']; } $this->m_oSet = new CMDBObjectSet($this->m_oFilter, array(), $aQueryParams); } $iCount = $this->m_oSet->Count(); $sHyperlink = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search&' . $oAppContext->GetForLink() . '&filter=' . urlencode($this->m_oFilter->serialize()); $sHtml .= '<p><a class="actions" href="' . $sHyperlink . '">'; // Note: border set to 0 due to various browser interpretations (IE9 adding a 2px border) $sHtml .= MetaModel::GetClassIcon($sClass, true, 'float;left;margin-right:10px;border:0;'); $sHtml .= MetaModel::GetName($sClass) . ': ' . $iCount . '</a></p>'; $sParams = $oAppContext->GetForLink(); $sHtml .= '<p>'; if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY)) { $sHtml .= "<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=new&class={$sClass}&{$sParams}\">" . Dict::Format('UI:ClickToCreateNew', MetaModel::GetName($sClass)) . "</a><br/>\n"; } $sHtml .= "<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=search_form&do_search=0&class={$sClass}&{$sParams}\">" . Dict::Format('UI:SearchFor_Class', MetaModel::GetName($sClass)) . "</a>\n"; $sHtml .= '</p>'; break; case 'summary': $sClass = $this->m_oFilter->GetClass(); $oAppContext = new ApplicationContext(); $sTitle = isset($aExtraParams['title[block]']) ? $aExtraParams['title[block]'] : ''; $sLabel = isset($aExtraParams['label[block]']) ? $aExtraParams['label[block]'] : ''; $sStateAttrCode = isset($aExtraParams['status[block]']) ? $aExtraParams['status[block]'] : 'status'; $sStatesList = isset($aExtraParams['status_codes[block]']) ? $aExtraParams['status_codes[block]'] : ''; $bContextFilter = isset($aExtraParams['context_filter']) ? isset($aExtraParams['context_filter']) != 0 : false; if ($bContextFilter) { $aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($this->m_oFilter->GetClass())); foreach ($oAppContext->GetNames() as $sFilterCode) { $sContextParamValue = $oAppContext->GetCurrentValue($sFilterCode, null); if (!is_null($sContextParamValue) && !empty($sContextParamValue) && MetaModel::IsValidFilterCode($sClass, $sFilterCode)) { $this->AddCondition($sFilterCode, $sContextParamValue); } } $aQueryParams = array(); if (isset($aExtraParams['query_params'])) { $aQueryParams = $aExtraParams['query_params']; } $this->m_oSet = new CMDBObjectSet($this->m_oFilter, array(), $aQueryParams); } // Summary details $aCounts = array(); $aStateLabels = array(); if (!empty($sStateAttrCode) && !empty($sStatesList)) { $aStates = explode(',', $sStatesList); $oAttDef = MetaModel::GetAttributeDef($sClass, $sStateAttrCode); foreach ($aStates as $sStateValue) { $oFilter = $this->m_oFilter->DeepClone(); $oFilter->AddCondition($sStateAttrCode, $sStateValue, '='); $oSet = new DBObjectSet($oFilter); $aCounts[$sStateValue] = $oSet->Count(); $aStateLabels[$sStateValue] = htmlentities($oAttDef->GetValueLabel($sStateValue), ENT_QUOTES, 'UTF-8'); if ($aCounts[$sStateValue] == 0) { $aCounts[$sStateValue] = '-'; } else { $sHyperlink = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search&' . $oAppContext->GetForLink() . '&filter=' . urlencode($oFilter->serialize()); $aCounts[$sStateValue] = "<a href=\"{$sHyperlink}\">{$aCounts[$sStateValue]}</a>"; } } } $sHtml .= '<div class="summary-details"><table><tr><th>' . implode('</th><th>', $aStateLabels) . '</th></tr>'; $sHtml .= '<tr><td>' . implode('</td><td>', $aCounts) . '</td></tr></table></div>'; // Title & summary $iCount = $this->m_oSet->Count(); $sHyperlink = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search&' . $oAppContext->GetForLink() . '&filter=' . urlencode($this->m_oFilter->serialize()); $sHtml .= '<h1>' . Dict::S(str_replace('_', ':', $sTitle)) . '</h1>'; $sHtml .= '<a class="summary" href="' . $sHyperlink . '">' . Dict::Format(str_replace('_', ':', $sLabel), $iCount) . '</a>'; $sHtml .= '<div style="clear:both;"></div>'; break; case 'csv': $bAdvancedMode = utils::ReadParam('advanced', false); $sCsvFile = strtolower($this->m_oFilter->GetClass()) . '.csv'; $sDownloadLink = utils::GetAbsoluteUrlAppRoot() . 'webservices/export.php?expression=' . urlencode($this->m_oFilter->ToOQL(true)) . '&format=csv&filename=' . urlencode($sCsvFile); $sLinkToToggle = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search&' . $oAppContext->GetForLink() . '&filter=' . urlencode($this->m_oFilter->serialize()) . '&format=csv'; if ($bAdvancedMode) { $sDownloadLink .= '&fields_advanced=1'; $sChecked = 'CHECKED'; } else { $sLinkToToggle = $sLinkToToggle . '&advanced=1'; $sChecked = ''; } $sAjaxLink = $sDownloadLink . '&charset=UTF-8'; // Includes &fields_advanced=1 if in advanced mode /* $sCSVData = cmdbAbstractObject::GetSetAsCSV($this->m_oSet, array('fields_advanced' => $bAdvancedMode)); $sCharset = MetaModel::GetConfig()->Get('csv_file_default_charset'); if ($sCharset == 'UTF-8') { $bLostChars = false; } else { $sConverted = @iconv('UTF-8', $sCharset, $sCSVData); $sRestored = @iconv($sCharset, 'UTF-8', $sConverted); $bLostChars = ($sRestored != $sCSVData); } if ($bLostChars) { $sCharsetNotice = " <span id=\"csv_charset_issue\">"; $sCharsetNotice .= '<img src="../images/error.png" style="vertical-align:middle"/>'; $sCharsetNotice .= "</span>"; $sTip = "<p>".htmlentities(Dict::S('UI:CSVExport:LostChars'), ENT_QUOTES, 'UTF-8')."</p>"; $sTip .= "<p>".htmlentities(Dict::Format('UI:CSVExport:LostChars+', $sCharset), ENT_QUOTES, 'UTF-8')."</p>"; $oPage->add_ready_script("$('#csv_charset_issue').qtip( { content: '$sTip', show: 'mouseover', hide: 'mouseout', style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );"); } else { $sCharsetNotice = ''; } */ $sCharsetNotice = false; $sHtml .= "<div>"; $sHtml .= '<table style="width:100%" class="transparent">'; $sHtml .= '<tr>'; $sHtml .= '<td><a href="' . $sDownloadLink . '">' . Dict::Format('UI:Download-CSV', $sCsvFile) . '</a>' . $sCharsetNotice . '</td>'; $sHtml .= '<td style="text-align:right"><input type="checkbox" ' . $sChecked . ' onClick="window.location.href=\'' . $sLinkToToggle . '\'"> ' . Dict::S('UI:CSVExport:AdvancedMode') . '</td>'; $sHtml .= '</tr>'; $sHtml .= '</table>'; if ($bAdvancedMode) { $sHtml .= "<p>"; $sHtml .= htmlentities(Dict::S('UI:CSVExport:AdvancedMode+'), ENT_QUOTES, 'UTF-8'); $sHtml .= "</p>"; } $sHtml .= "</div>"; $sHtml .= "<div id=\"csv_content_loading\"><div style=\"width: 250px; height: 20px; background: url(../setup/orange-progress.gif); border: 1px #999 solid; margin-left:auto; margin-right: auto; text-align: center;\">" . Dict::S('UI:Loading') . "</div></div><textarea id=\"csv_content\" style=\"display:none;\">\n"; //$sHtml .= htmlentities($sCSVData, ENT_QUOTES, 'UTF-8'); $sHtml .= "</textarea>\n"; $oPage->add_ready_script("\$.post('{$sAjaxLink}', {}, function(data) { \$('#csv_content').html(data); \$('#csv_content_loading').hide(); \$('#csv_content').show();} );"); break; case 'modify': if (UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_MODIFY, $this->m_oSet) == UR_ALLOWED_YES) { while ($oObj = $this->m_oSet->Fetch()) { $sHtml .= $oObj->GetModifyForm($oPage); } } break; case 'search': $sStyle = isset($aExtraParams['open']) && $aExtraParams['open'] == 'true' ? 'SearchDrawer' : 'SearchDrawer DrawerClosed'; $sHtml .= "<div id=\"ds_{$sId}\" class=\"{$sStyle}\">\n"; $oPage->add_ready_script(<<<EOF \t\$("#dh_{$sId}").click( function() { \t\t\$("#ds_{$sId}").slideToggle('normal', function() { \$("#ds_{$sId}").parent().resize(); FixSearchFormsDisposition(); } ); \t\t\$("#dh_{$sId}").toggleClass('open'); \t}); EOF ); $aExtraParams['currentId'] = $sId; $sHtml .= cmdbAbstractObject::GetSearchForm($oPage, $this->m_oSet, $aExtraParams); $sHtml .= "</div>\n"; $sHtml .= "<div class=\"HRDrawer\"></div>\n"; $sHtml .= "<div id=\"dh_{$sId}\" class=\"DrawerHandle\">" . Dict::S('UI:SearchToggle') . "</div>\n"; break; case 'open_flash_chart': static $iChartCounter = 0; $oAppContext = new ApplicationContext(); $sContext = $oAppContext->GetForLink(); if (!empty($sContext)) { $sContext = '&' . $sContext; } $sChartType = isset($aExtraParams['chart_type']) ? $aExtraParams['chart_type'] : 'pie'; $sTitle = isset($aExtraParams['chart_title']) ? $aExtraParams['chart_title'] : ''; $sGroupBy = isset($aExtraParams['group_by']) ? $aExtraParams['group_by'] : ''; $sGroupByExpr = isset($aExtraParams['group_by_expr']) ? '¶ms[group_by_expr]=' . $aExtraParams['group_by_expr'] : ''; $sFilter = $this->m_oFilter->serialize(); $sHtml .= "<div id=\"my_chart_{$sId}{$iChartCounter}\">If the chart does not display, <a href=\"http://get.adobe.com/flash/\" target=\"_blank\">install Flash</a></div>\n"; $oPage->add_script("function ofc_resize(left, width, top, height) { /* do nothing special */ }"); if (isset($aExtraParams['group_by_label'])) { $sUrl = urlencode(utils::GetAbsoluteUrlAppRoot() . "pages/ajax.render.php?operation=open_flash_chart¶ms[group_by]={$sGroupBy}{$sGroupByExpr}¶ms[group_by_label]={$aExtraParams['group_by_label']}¶ms[chart_type]={$sChartType}¶ms[chart_title]={$sTitle}¶ms[currentId]={$sId}&id={$sId}&filter=" . urlencode($sFilter)); } else { $sUrl = urlencode(utils::GetAbsoluteUrlAppRoot() . "pages/ajax.render.php?operation=open_flash_chart¶ms[group_by]={$sGroupBy}{$sGroupByExpr}¶ms[chart_type]={$sChartType}¶ms[chart_title]={$sTitle}¶ms[currentId]={$sId}&id={$sId}&filter=" . urlencode($sFilter)); } $oPage->add_ready_script("swfobject.embedSWF(\"../images/open-flash-chart.swf\", \"my_chart_{$sId}{$iChartCounter}\", \"100%\", \"300\",\"9.0.0\", \"expressInstall.swf\",\n\t\t\t\t{\"data-file\":\"" . $sUrl . "\"}, {wmode: 'transparent'} );\n"); $iChartCounter++; if (isset($aExtraParams['group_by'])) { if (isset($aExtraParams['group_by_label'])) { $oGroupByExp = Expression::FromOQL($aExtraParams['group_by']); $sGroupByLabel = $aExtraParams['group_by_label']; } else { // Backward compatibility: group_by is simply a field id $sAlias = $this->m_oFilter->GetClassAlias(); $oGroupByExp = new FieldExpression($aExtraParams['group_by'], $sAlias); $sGroupByLabel = MetaModel::GetLabel($this->m_oFilter->GetClass(), $aExtraParams['group_by']); } $aGroupBy = array(); $aGroupBy['grouped_by_1'] = $oGroupByExp; $sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy, true); $aRes = CMDBSource::QueryToArray($sSql); $aGroupBy = array(); $aLabels = array(); $aValues = array(); $iTotalCount = 0; foreach ($aRes as $iRow => $aRow) { $sValue = $aRow['grouped_by_1']; $aValues[$iRow] = $sValue; $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue); $aLabels[$iRow] = $sHtmlValue; $aGroupBy[$iRow] = (int) $aRow['_itop_count_']; $iTotalCount += $aRow['_itop_count_']; } $aData = array(); $idx = 0; $aURLs = array(); foreach ($aGroupBy as $iRow => $iCount) { // Build the search for this subset $oSubsetSearch = $this->m_oFilter->DeepClone(); $oCondition = new BinaryExpression($oGroupByExp, '=', new ScalarExpression($aValues[$iRow])); $oSubsetSearch->AddConditionExpression($oCondition); $aURLs[$idx] = $oSubsetSearch->serialize(); $idx++; } $sURLList = ''; foreach ($aURLs as $index => $sURL) { $sURLList .= "\taURLs[{$index}] = '" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=search&format=html{$sContext}&filter=" . urlencode($sURL) . "';\n"; } $oPage->add_script(<<<EOF function ofc_drill_down_{$sId}(index) { \tvar aURLs = new Array(); {$sURLList} \twindow.location.href=aURLs[index]; } EOF ); } break; case 'open_flash_chart_ajax': require_once APPROOT . '/pages/php-ofc-library/open-flash-chart.php'; $sChartType = isset($aExtraParams['chart_type']) ? $aExtraParams['chart_type'] : 'pie'; $sId = utils::ReadParam('id', ''); $oChart = new open_flash_chart(); switch ($sChartType) { case 'bars': $oChartElement = new bar_glass(); if (isset($aExtraParams['group_by'])) { if (isset($aExtraParams['group_by_label'])) { $oGroupByExp = Expression::FromOQL($aExtraParams['group_by']); $sGroupByLabel = $aExtraParams['group_by_label']; } else { // Backward compatibility: group_by is simply a field id $sAlias = $this->m_oFilter->GetClassAlias(); $oGroupByExp = new FieldExpression($aExtraParams['group_by'], $sAlias); $sGroupByLabel = MetaModel::GetLabel($this->m_oFilter->GetClass(), $aExtraParams['group_by']); } $aGroupBy = array(); $aGroupBy['grouped_by_1'] = $oGroupByExp; $sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy, true); $aRes = CMDBSource::QueryToArray($sSql); $aGroupBy = array(); $aLabels = array(); $iTotalCount = 0; foreach ($aRes as $iRow => $aRow) { $sValue = $aRow['grouped_by_1']; $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue); $aLabels[$iRow] = strip_tags($sHtmlValue); $aGroupBy[$iRow] = (int) $aRow['_itop_count_']; $iTotalCount += $aRow['_itop_count_']; } $aData = array(); $aChartLabels = array(); $maxValue = 0; foreach ($aGroupBy as $iRow => $iCount) { $oBarValue = new bar_value($iCount); $oBarValue->on_click("ofc_drill_down_{$sId}"); $aData[] = $oBarValue; if ($iCount > $maxValue) { $maxValue = $iCount; } $aChartLabels[] = html_entity_decode($aLabels[$iRow], ENT_QUOTES, 'UTF-8'); } $oYAxis = new y_axis(); $aMagicValues = array(1, 2, 5, 10); $iMultiplier = 1; $index = 0; $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier; while ($maxValue > $iTop) { $index++; $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier; if ($index % count($aMagicValues) == 0) { $iMultiplier = $iMultiplier * 10; } } //echo "oYAxis->set_range(0, $iTop, $iMultiplier);\n"; $oYAxis->set_range(0, $iTop, $iMultiplier); $oChart->set_y_axis($oYAxis); $oChartElement->set_values($aData); $oXAxis = new x_axis(); $oXLabels = new x_axis_labels(); // set them vertical $oXLabels->set_vertical(); // set the label text $oXLabels->set_labels($aChartLabels); // Add the X Axis Labels to the X Axis $oXAxis->set_labels($oXLabels); $oChart->set_x_axis($oXAxis); } break; case 'pie': default: $oChartElement = new pie(); $oChartElement->set_start_angle(35); $oChartElement->set_animate(true); $oChartElement->set_tooltip('#label# - #val# (#percent#)'); $oChartElement->set_colours(array('#FF8A00', '#909980', '#2C2B33', '#CCC08D', '#596664')); if (isset($aExtraParams['group_by'])) { if (isset($aExtraParams['group_by_label'])) { $oGroupByExp = Expression::FromOQL($aExtraParams['group_by']); $sGroupByLabel = $aExtraParams['group_by_label']; } else { // Backward compatibility: group_by is simply a field id $sAlias = $this->m_oFilter->GetClassAlias(); $oGroupByExp = new FieldExpression($aExtraParams['group_by'], $sAlias); $sGroupByLabel = MetaModel::GetLabel($this->m_oFilter->GetClass(), $aExtraParams['group_by']); } $aGroupBy = array(); $aGroupBy['grouped_by_1'] = $oGroupByExp; $sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy, true); $aRes = CMDBSource::QueryToArray($sSql); $aGroupBy = array(); $aLabels = array(); $iTotalCount = 0; foreach ($aRes as $iRow => $aRow) { $sValue = $aRow['grouped_by_1']; $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue); $aLabels[$iRow] = strip_tags($sHtmlValue); $aGroupBy[$iRow] = (int) $aRow['_itop_count_']; $iTotalCount += $aRow['_itop_count_']; } $aData = array(); foreach ($aGroupBy as $iRow => $iCount) { $sFlashLabel = html_entity_decode($aLabels[$iRow], ENT_QUOTES, 'UTF-8'); $PieValue = new pie_value($iCount, $sFlashLabel); //@@ BUG: not passed via ajax !!! $PieValue->on_click("ofc_drill_down_{$sId}"); $aData[] = $PieValue; } $oChartElement->set_values($aData); $oChart->x_axis = null; } } if (isset($aExtraParams['chart_title'])) { // The title has been given in an url, and urlencoded... // and urlencode transforms utf-8 into something similar to ISO-8859-1 // Example: é (C3A9 becomes %E9) // As a consequence, json_encode (called within open-flash-chart.php) // was returning 'null' and the graph was not displayed at all // To make sure that the graph is displayed AND to get a correct title // (at least for european characters) let's transform back into utf-8 ! $sTitle = iconv("ISO-8859-1", "UTF-8//IGNORE", $aExtraParams['chart_title']); // If the title is a dictionnary entry, fetch it $sTitle = Dict::S($sTitle); $oTitle = new title($sTitle); $oChart->set_title($oTitle); $oTitle->set_style("{font-size: 16px; font-family: Tahoma; font-weight: bold; text-align: center;}"); } $oChart->set_bg_colour('#FFFFFF'); $oChart->add_element($oChartElement); $sHtml = $oChart->toPrettyString(); break; default: // Unsupported style, do nothing. $sHtml .= Dict::format('UI:Error:UnsupportedStyleOfBlock', $this->m_sStyle); } return $sHtml; }
/** * assign the chartdata object for open flash chart library * @param $config * @return unknown_type */ function _setChartdata($config) { $model = $this->getModel(); $rounds = $this->get('Rounds'); $round_labels = array(); foreach ($rounds as $r) { $round_labels[] = $r->name; } $division = $this->get('division'); $data = $model->getDataByDivision($division->id); //create a line $length = count($rounds) - 0.5; $linewidth = $config['color_legend_line_width']; $lines = array(); //$title = $division->name; $chart = new open_flash_chart(); //$chart->set_title( $title ); $chart->set_bg_colour($config['bg_colour']); //colors defined for ranking table lines //todo: add support for more than 2 lines foreach ($this->colors as $color) { foreach ($rounds as $r) { for ($n = $color['from']; $n <= $color['to']; $n++) { $lines[$color['color']][$n][] = $n; } } } //set lines on the graph foreach ($lines as $key => $value) { foreach ($value as $line => $key2) { $chart->add_element(hline($key, $length, $line, $linewidth)); } } //load team1, first team in the dropdown $team = $this->team1; $d = new $config['dotstyle_1'](); $d->size((int) $config['line1_dot_strength']); $d->halo_size(1); $d->colour($config['line1']); $d->tooltip('Rank: #val#'); $line = new line(); $line->set_default_dot_style($d); $line->set_values($team->rankings); $line->set_width((int) $config['line1_strength']); $line->set_key($team->name, 12); $line->set_colour($config['line1']); $line->on_show(new line_on_show($config['l_animation_1'], $config['l_cascade_1'], $config['l_delay_1'])); $chart->add_element($line); //load team2, second team in the dropdown $team = $this->team2; $d = new $config['dotstyle_2'](); $d->size((int) $config['line2_dot_strength']); $d->halo_size(1); $d->colour($config['line2']); $d->tooltip('Rank: #val#'); $line = new line(); $line->set_default_dot_style($d); $line->set_values($team->rankings); $line->set_width((int) $config['line2_strength']); $line->set_key($team->name, 12); $line->set_colour($config['line2']); $line->on_show(new line_on_show($config['l_animation_2'], $config['l_cascade_2'], $config['l_delay_2'])); $chart->add_element($line); $x = new x_axis(); if ($config['x_axis_label'] == 1) { $xlabels = new x_axis_labels(); $xlabels->set_labels($round_labels); $xlabels->set_vertical(); } $x->set_labels($xlabels); $x->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']); $chart->set_x_axis($x); $x_legend = new x_legend(JText::_('COM_JOOMLEAGUE_CURVE_ROUNDS')); $x_legend->set_style('{font-size: 15px; color: #778877}'); $chart->set_x_legend($x_legend); $y = new y_axis(); $y->set_range(count($data), 1, -1); $y->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']); $chart->set_y_axis($y); $y_legend = new y_legend(JText::_('COM_JOOMLEAGUE_CURVE_RANK')); $y_legend->set_style('{font-size: 15px; color: #778877}'); $chart->set_y_legend($y_legend); ob_clean(); echo $chart->toString(); }
$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';
private function getChart($aGraphs) { $this->prepareData(); $oLabels = new x_axis_labels(); $oLabels->set_labels($this->aData[0]); $oLabels->rotate(-45); $oX = new x_axis(); $oX->set_labels($oLabels); $oX->set_colours('#000000', '#ffffff'); $oChart = new open_flash_chart(); $oChart->set_bg_colour('#FFFFFF'); $oTitle = new title($this->getTitle()); $oTitle->set_style('font-size: 12px; font-weight: bold;'); $oChart->set_title($oTitle); $oTooltip = new tooltip('#val#'); $oTooltip->set_body_style('font-size: 10px'); $oTooltip->set_stroke(1); $oTooltip->set_shadow(true); $oTooltip->set_background_colour('#ffffcc'); $oTooltip->set_colour('#cccc99'); $oChart->set_tooltip($oTooltip); $aY = array(); foreach ($aGraphs as $k => $v) { $y = empty($v['y-right']) ? 0 : 1; $scale = empty($v['scale']) ? 1 : $v['scale']; if (!isset($aY[$y])) { $aY[$y] = new y_axis(); $aY[$y]->set_colours($v['colour'], '#f6f6f6'); } if (empty($v['y-remap'])) { $this->setAxisRange($aY[$y], $k, $scale); } else { $this->remapSeries($aY[$y], $k, $scale); } $oSeries = $this->getSeries($k, $v['type'], $v['colour']); if (!empty($this->drillDown)) { $oSeries->set_on_click($this->drillDown); } $oSeries->set_on_show($v['effect']); if ($y) { $oSeries->attach_to_right_y_axis(); } $aGraphs[$k] = $oSeries; } $oChart->set_x_axis($oX); foreach ($aY as $y => $e) { $method = $y ? 'set_y_axis_right' : 'set_y_axis'; $oChart->{$method}($e); } foreach ($aGraphs as $e) { $oChart->add_element($e); } return $oChart; }
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(); }
'); $deposits = array(); $withdrawals = array(); $weeks = array(); while ($row = mysql_fetch_assoc($result)) { $weeks[] = date('d.m.Y', $row['stamp']); $deposits[] = round($row['deposits'], 2); $withdrawals[] = -round($row['withdrawals'], 2); } //lines $line1 = new line(); $line1->set_values($deposits); $line1->set_colour('#00FF00'); $line2 = new line(); $line2->set_values($withdrawals); $line2->set_colour('#FF0000'); //axises $axis_x = new x_axis(); $axis_x_labels = new x_axis_labels(); $axis_x_labels->set_labels($weeks); $axis_x->set_labels($axis_x_labels); $axis_y = new y_axis(); $axis_y->range(0, max(max($deposits), max($withdrawals)), 1000); //chart $chart = new open_flash_chart(); $chart->set_y_axis($axis_y); $chart->set_x_axis($axis_x); $chart->add_element($line1); $chart->add_element($line2); $chart->set_bg_colour('#FFFFFF'); echo $chart->toPrettyString();
} } } } $title = new title($title); $title->set_style("{font-size: 20px; color: #A2ACBA; text-align: center;}"); $bar = new bar_3d(); $bar->set_values($data); $bar->colour = '#D54C78'; $x_labels = new x_axis_labels(); $x_labels->set_labels($x_date); $x_axis = new x_axis(); $x_axis->set_3d(3); $x_axis->colour = '#909090'; $x_axis->set_labels($x_labels); $x_legend = new x_legend($x_title); $x_legend->set_style('{font-size: 20px; color: #778877}'); $y_axis = new y_axis(); $max = arr_max($data); $mix = arr_min($data); $per = round($max / 10); $max = round($max + $per + $per); $temp = '$y_axis->set_range(0,' . $max . ',' . $per . ');'; eval($temp); $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($bar); $chart->set_x_axis($x_axis); $chart->set_x_legend($x_legend); $chart->set_y_axis($y_axis); echo $chart->toPrettyString();
function _render_statistic($x = array(), $yout = array(), $yin = array(), $type = 'bar', $points) { $this->load->helper('date'); $this->load->library('OpenFlashChartLib', NULL, 'OFCL'); $data_1 = array(); $data_2 = array(); $data_3 = array(); switch ($type) { case 'bar': for ($i = 0; $i <= $points; $i++) { $data_1[$i] = $x[$i]; $data_2[$i] = (int) $yout[$i]; // force to integer $data_3[$i] = (int) $yin[$i]; // force to integer } $data_1 = array_reverse($data_1); $data_2 = array_reverse($data_2); $data_3 = array_reverse($data_3); $bar_1 = new bar(); $bar_1->set_values($data_3); $bar_1->set_colour('#639F45'); $bar_1->key(lang('kalkun_incoming_sms'), 10); $bar_1->set_tooltip('#x_label#<br>#val# SMS'); //$bar_1->set_key("SMS used in last 7 days", 10); $bar_2 = new bar(); $bar_2->set_values($data_2); $bar_2->set_colour('#21759B'); $bar_2->key(lang('kalkun_outgoing_sms'), 10); $bar_2->set_tooltip('#x_label#<br>#val# SMS'); $x = new x_axis(); $labels = new x_axis_labels(); $labels->set_labels($data_1); $labels->set_steps(1); $x->set_labels($labels); $y = new y_axis(); $max = max(max($data_2), max($data_3)); if ($max < 10) { $max = 10; } $max = ceil($max / 5) * 5; $range = ceil($max / 5); $range = ceil($range / 10) * 10; $y->set_range(0, $max, $range); $element1 = $bar_1; $element2 = $bar_2; break; case 'line': for ($i = 0; $i <= 7; $i++) { $data_1[$i] = new scatter_value($x[$i], $yin[$i]); $data_2[$i] = new scatter_value($x[$i], $yout[$i]); $data_3[$i] = (int) $yin[$i]; $data_4[$i] = (int) $yout[$i]; } $def = new solid_dot(); $def->size(4)->halo_size(0)->colour('#21759B')->tooltip('#date:d M y#<br>#val# SMS'); $line_1 = new scatter_line('#639F45', 3); $line_1->set_values($data_1); $line_1->set_default_dot_style($def); $line_1->set_key("Incoming SMS", 10); $line_2 = new scatter_line('#21759B', 3); $line_2->set_values($data_2); $line_2->set_default_dot_style($def); $line_2->set_key("Outgoing SMS", 10); $x = new x_axis(); // grid line and tick every 10 $x->set_range(mktime(0, 0, 0, date("m"), date("d") - 7, date('Y')), mktime(0, 0, 0, date("m"), date("d"), date('Y'))); // show ticks and grid lines for every day: $x->set_steps(86400); $labels = new x_axis_labels(); // tell the labels to render the number as a date: $labels->text('#date:M-d#'); // generate labels for every day $labels->set_steps(86400); // only display every other label (every other day) $labels->visible_steps(1); $labels->rotate(45); // finally attach the label definition to the x axis $x->set_labels($labels); $y = new y_axis(); $max = max(max($data_3), max($data_4)); if ($max < 1) { $max = 10; } $y->set_range(0, $max, round($max / 100) * 10); $element1 = $line_1; $element2 = $line_2; break; } $chart = new open_flash_chart(); $chart->add_element($element1); $chart->add_element($element2); $chart->set_x_axis($x); $chart->set_y_axis($y); echo $chart->toPrettyString(); }
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 />"; }