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(); }
<?php require_once 'php-ofc-library/open-flash-chart.php'; // generate some random data srand((double) microtime() * 1000000); $max = 20; $tmp = array(); for ($i = 0; $i < 13; $i++) { $tmp[] = rand(0, $max); } $title = new title(date("D M d Y")); $bar = new bar(); $bar->set_values(array(3, 2, 3, 4, 5, 6, 7, 8, 9, 3, 12, 4)); $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($bar); $path = "data.json.inc"; $file = fopen($path, "w"); fwrite($file, $chart->toString()); fclose($file);
<?php include 'php-ofc-library/open-flash-chart.php'; // generate some random data srand((double) microtime() * 1000000); $max = 20; $tmp = array(); for ($i = 0; $i < 9; $i++) { $tmp[] = rand(0, $max); } $title = new title(date("D M d Y")); $bar = new bar(); $bar->set_values(array(1, 2, 3, 4, 5, 6, 7, 8, 9)); $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($bar); echo $chart->toString();
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 lists() { acymailing::setTitle(JText::_('CHARTS'), 'stats', 'diagram&task=lists'); $listsClass = acymailing::get('class.list'); $lists = $listsClass->getLists('listid'); $db =& JFactory::getDBO(); $db->setQuery('SELECT listid, count(subid) as total FROM ' . acymailing::table('listsub') . ' WHERE `status` = 1 group by listid'); $subscribers = $db->loadObjectList('listid'); $db->setQuery('SELECT listid, count(subid) as total FROM ' . acymailing::table('listsub') . ' WHERE `status` = -1 group by listid'); $unsubscribers = $db->loadObjectList('listid'); $db->setQuery('SELECT listid, count(subid) as total FROM ' . acymailing::table('listsub') . ' WHERE `status` = 2 group by listid'); $waitsub = $db->loadObjectList('listid'); $title = new title(JText::_('NB_SUB_UNSUB')); $title->set_style('font-size:20px; color: #FF8040'); $xLabels = array(); $subColumn = array(); $unsubColumn = array(); $waitColumn = array(); foreach ($lists as $listid => $oneList) { $xLabels[] = $oneList->name; $subColumn[] = empty($subscribers[$listid]->total) ? 0 : (int) $subscribers[$listid]->total; $unsubColumn[] = empty($unsubscribers[$listid]->total) ? 0 : (int) $unsubscribers[$listid]->total; $waitColumn[] = empty($waitsub[$listid]->total) ? 0 : (int) $waitsub[$listid]->total; } $barSub = new bar(); $barSub->set_values($subColumn); $barSub->set_colour('#00FF00'); $barSub->set_tooltip(JText::_('SUBSCRIBERS') . ' : #val#'); $barUnsub = new bar(); $barUnsub->set_values($unsubColumn); $barUnsub->set_colour('#CC0000'); $barUnsub->set_tooltip(JText::_('UNSUBSCRIBERS') . ' : #val#'); if (!empty($waitsub)) { $barWait = new bar(); $barWait->set_values($waitColumn); $barWait->set_tooltip(JText::_('PENDING_SUBSCRIPTION') . ' : #val#'); $barWait->set_colour('#FF9900'); } $maxSub = max($subColumn); $maxUnsub = max($unsubColumn); $maxWait = max($waitColumn); $yLabels[] = JText::_('SUBSCRIBERS'); $yLabels[] = JText::_('UNSUBSCRIBERS'); $x_axis = new x_axis(); $xlabelobject = new x_axis_labels(); $xlabelobject->rotate(-20); $xlabelobject->set_labels($xLabels); $x_axis->set_labels($xlabelobject); $y_axis = new y_axis(); $maxYValue = max(array($maxSub, $maxUnsub, $maxWait)); $y_axis->range(0, $maxYValue, intval($maxYValue / 10)); $chart = new open_flash_chart(); $chart->set_title($title); $chart->set_x_axis($x_axis); $chart->set_y_axis($y_axis); if (!empty($waitsub)) { $chart->add_element($barWait); } $chart->add_element($barSub); $chart->add_element($barUnsub); $this->assignRef('chart', $chart); }
$chart->add_element($bar); $chart->set_x_axis($x_axis); echo $chart->toPrettyString(); break; case "4": // penghasilan srand((double) microtime() * 1000000); $data = array(); // add random height bars: for ($i = 0; $i < 10; $i++) { $data[] = rand(2, 9); } require_once '../php-ofc-library/open-flash-chart.php'; $title = new title("Penghasilan Penduduk "); $bar = new bar(); $bar->set_values($data); $bar->colour = '#D54C78'; $x_axis = new x_axis(); $x_axis->set_colour('#909090'); $x_axis->set_labels_from_array(array("Gedangan", "Sawo", "3", "4", "5", "6", "7", "8", "9", "10")); $y_axis = new y_axis(); $y_axis->set_label_text(array("Make garden look sexy", "Paint house", "Move into house")); $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); echo $chart->toPrettyString(); break; case "5": $additional = array();