function customizeGraph() { parent::customizeGraph(); $this->prepareData(); $this->set_y_max($this->maxData); $line_1 = new line_hollow(1, 3, '0x3357A0'); $line_1->key('visits', 10); $i = 0; foreach ($this->arrayData as $value) { // hack until we have proper date handling $spacePosition = strpos($this->arrayLabel[$i], ' '); if ($spacePosition === false) { $spacePosition = strlen($this->arrayLabel[$i]); } // generate the link on the dot, to the given day' statistics $link = Piwik_Url::getCurrentScriptName() . Piwik_Url::getCurrentQueryStringWithParametersModified(array('date' => substr($this->arrayLabel[$i], 0, $spacePosition), 'module' => 'Home', 'action' => 'index', 'viewDataTable' => null)); $line_1->add_link($value, $link); $i++; } $this->data_sets[] = $line_1; $this->set_x_labels($this->arrayLabel); $this->area_hollow(1, 3, 4, '0x3357A0', ' visits', 10); }
function grafico($mes = NULL, $anio = NULL) { if (empty($mes) and empty($anio)) { return; } $this->load->library('Graph'); $titulo = $data_1 = $data_2 = $data_3 = $data_tips_1 = $data_tips_2 = $data_tips_3 = array(); $fechai = $anio . str_pad($mes, 2, "0", STR_PAD_LEFT) . '01'; $fechaf = $anio . str_pad($mes, 2, "0", STR_PAD_LEFT) . '31'; $data = $this->_sincrodata($fechai, $fechaf); $om = 1; while ($this->maxval / $om > 100) { $om = $om * 10; } foreach ($data as $row) { $titulo[] = $row['dia']; $data_1[] = $row['contado'] / $om; $data_2[] = $row['credito'] / $om; $data_3[] = $row['cobrado'] / $om; $data_tips_1[] = graph::esc(number_format($row['contado'], 2, ',', '.')); $data_tips_2[] = graph::esc(number_format($row['credito'], 2, ',', '.')); $data_tips_3[] = graph::esc(number_format($row['cobrado'], 2, ',', '.')); } $odata_1 = new bar_fade(50, '0xCC3399'); $odata_1->key('Contado', 10); $odata_1->data = $data_1; $odata_1->tips = $data_tips_1; $odata_2 = new bar_fade(50, '0x80a033'); $odata_2->key('Crédito', 10); $odata_2->data = $data_2; $odata_2->tips = $data_tips_2; $odata_3 = new line_hollow(2, 3, '0x9933CC'); $odata_3->key('Cobranzas a Crédito', 10); $odata_3->data = $data_3; $odata_3->tips = $data_tips_3; $g = new Graph(); if ($this->maxval > 0) { $g->title('Ventas del mes ' . $mes . '/' . $anio, '{font-size:18px; color: #d01f3c}'); $g->set_is_decimal_separator_comma(1); $g->data_sets[] = $odata_3; $g->data_sets[] = $odata_1; $g->data_sets[] = $odata_2; $g->set_y_max(ceil($this->maxval / $om)); $g->y_label_steps(5); $g->set_x_labels($titulo); $ejey = number_format($om, 0, '', '.'); $g->set_y_legend('Venta X ' . $ejey . ' (Bs)', 14, '0x639F45'); $g->set_x_legend('Días del mes ' . $mes, 14, '0x639F45'); $g->set_tool_tip('#key#<br>Día: #x_label# <br>Monto: #tip#'); } else { $g->title('No existen ventas en la Fecha Seleccionada', '{font-size:18px; color: #d01f3c}'); } $g->bg_colour = '#FFFFFF'; //$g->set_bg_image(site_url('/images/ventafon.png'), 'center', 'middle' ); echo utf8_encode($g->render()); }
/** * Alias for FlashChart::chart('radar'); * * The Radar chart needs special axis and also * have special methods for stokes and labes * * @todo Each value can have it's own tooltip using the dot_value class * * @example echo $flashChart->radar(array('loop'=>false','colour'=>'336699')); * @example echo $flashChart->radar(array('type'=>filled'),'Dataset2'); * @param array $options * @param string $datasetName The name to be used to associate charts with data * @param string $chartId Name of chart. Use for seperate charts. * @return string */ public function radar($options = array(), $datasetName = 'default', $chartId = 'default') { if (empty($this->data[$datasetName])) { return false; } $this->Chart->set_bg_colour($this->bg_colour); if (isset($options['type']) && $options['type'] == 'filled') { $line = new area_hollow(); } else { $line = new line_hollow(); if (!isset($options['loop']) || isset($options['loop']) && $options['loop']) { $line->loop(); } if (isset($options['loop'])) { unset($options['loop']); } } $values = $this->getNumbers($datasetName); /* @todo code below is not getting expected result if (isset($options['tooltip_path'])) { $numbers = $values; $values = array(); $tooltips = Set::extract($xpath,$this->data[$datasetName]); if (isset($options['tooltip_colour'])) { $colour = $options['tooltip_colour']; unset($options['tooltip_colour']); } else { $colour = $this->grid_colour; } foreach ($numbers as $key => $number) { $tmp = new dot_value( $number, $colour ); $tmp->set_tooltip($tooltips[$key]); $values[] = $tmp; } unset($options['tooltip_path']); }*/ if (isset($options['type'])) { unset($options['type']); } foreach ($options as $key => $setting) { $set_method = 'set_' . $key; if (is_array($setting)) { $line->{$set_method}($setting[0], $setting[1]); } else { $line->{$set_method}($setting); } } $radar_axis_object = new radar_axis($this->radarAxis['max']); $radar_axis_object->set_steps($this->radarAxis['steps']); $radar_axis_object->set_colour($this->radarAxis['colour']); $radar_axis_object->set_grid_colour($this->radarAxis['grid_colour']); if (!empty($this->radarAxis['labels'])) { $labels = new radar_axis_labels($this->radarAxis['labels']); $labels->set_colour($this->radarAxis['label_colour']); $radar_axis_object->set_labels($labels); } if (!is_null($this->spoke_labels)) { $radar_axis_object->set_spoke_labels($this->spoke_labels); } $this->Chart->set_radar_axis($radar_axis_object); $line->set_values($values); $this->Chart->add_element($line); return $this->renderData($chartId); }
function line_dot($line_width, $dot_size, $colour) { parent::line_dot($line_width, $colour); $this->var = 'line_dot'; }
function grafico($anio = '') { if (empty($anio)) { return; } $this->load->library('Graph'); $titulo = $data_1 = $data_2 = $data_3 = $data_tips_1 = $data_tips_2 = $data_tips_3 = array(); $fechai = $anio . '0101'; $fechaf = $anio . '1231'; $data = $this->_sincrodata($fechai, $fechaf); $om = 1; while ($this->maxval / $om > 100) { $om = $om * 10; } //print_r($data); foreach ($data as $row) { $titulo[] = $row['mes']; $data_1[] = $row['contado'] / $om; $data_2[] = $row['credito'] / $om; $data_3[] = $row['cobrado'] / $om; $data_tips_1[] = graph::esc(number_format($row['contado'], 2, ',', '.')); $data_tips_2[] = graph::esc(number_format($row['credito'], 2, ',', '.')); $data_tips_3[] = graph::esc(number_format($row['cobrado'], 2, ',', '.')); } $odata_1 = new bar_fade(50, '0xCC3399'); $odata_1->key('Contado', 10); $odata_1->data = $data_1; $odata_1->tips = $data_tips_1; $odata_2 = new bar_fade(50, '0x80a033'); $odata_2->key('Crédito', 10); $odata_2->data = $data_2; $odata_2->tips = $data_tips_2; $odata_4 = new line_hollow(2, 3, '0x9933CC'); $odata_4->key('Cobranzas a Crédito', 10); $odata_4->data = $data_3; $odata_4->tips = $data_tips_3; for ($i = 0; $i < count($data_1); $i++) { $mes = $i + 1; $odata_1->links[] = site_url("/hospitalidad/mensuales/index/{$mes}/{$anio}"); $odata_2->links[] = site_url("/hospitalidad/mensuales/index/{$mes}/{$anio}"); $odata_3->links[] = site_url("/hospitalidad/mensuales/index/{$mes}/{$anio}"); } $g = new Graph(); $g->set_is_decimal_separator_comma(1); if ($this->maxval > 0) { $g->title('Ventas en el año ' . $anio, '{font-size:18px; color: #d01f3c}'); $g->data_sets[] = $odata_1; $g->data_sets[] = $odata_2; $g->data_sets[] = $odata_4; $g->set_y_max(ceil($this->maxval / $om)); $g->y_label_steps(5); $g->set_x_labels($titulo); $ejey = number_format($om, 0, '', ' '); $g->set_y_legend('Venta X ' . $ejey . ' (Bs)', 14, '0x639F45'); $g->set_x_legend('Meses', 14, '0x639F45'); $g->set_tool_tip('#key#<br>Mes: #x_label# <br>Monto: #tip#'); } else { $g->title('NO existen ventas en el año seleccionado', '{font-size:18px; color: #d01f3c}'); } $g->bg_colour = '#FFFFFF'; echo utf8_encode($g->render()); }
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 />"; }
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(); }