} else { while ($row = mysql_fetch_object($ok)) { $time_axis[] = date("H:i", strtotime($row->Time)); $data_watt[] = round((double) $row->Watt, 3); //$data_max[] = round((float)$row->maxWatt,3) ; $data_tot[] = round((double) $row->ETotal, 3); } $chart = new open_flash_chart(); if (count($time_axis) == 0) { echo 0; exit; } $title = new title("\n" . date('l dS F Y', $time) . " (" . round(max($data_tot) - min($data_tot), 2) . " kWh)"); $title->set_style('{font-size: 20px; color: #778877;}'); $tooltip = new tooltip(); $tooltip->set_hover(); $sline = new scatter_line('#3D3D3D', 3); $def = new hollow_dot(); $def->size(0)->halo_size(0); $sline->set_default_dot_style($def); $sline->set_key('Leistung (W)', 11); $v = array(); foreach ($data_watt as $key => $val) { $v[] = new scatter_value($key, $val); $v[] = new scatter_value($key + 1, $val); } $sline->set_values($v); $bars_curr = new bar_glass(); $bars_curr->set_key('Leistung (W)', 10); $bars_curr->set_colour('#EFC01D'); $bars_curr->set_alpha(0.8);
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; }
function stacked_bar_chart($host_instance_list) { $title = new title('所有instance实际内存使用'); $title->set_style("{color: #567300; font-size: 16px; font-weight:bold;}"); $bar_stack = new bar_stack(); $bar_stack->set_colours(array('#C4D318', '#7D7B6A')); $max = 64; foreach ($host_instance_list as $i => $instance) { $jvmmem = isset($instance['jvmmem']) ? explode('/', $instance['jvmmem']) : array(); if ($jvmmem) { foreach ($jvmmem as &$j) { $j = intval($j); } $max = $max < $jvmmem[1] ? $jvmmem[1] : $max; $jvmmem[1] = $jvmmem[1] - $jvmmem[0]; } $bar_stack->append_stack($jvmmem); $lables[] = $instance['port_num']; $services[$i] = $instance['service_name']; } $bar_stack->set_keys(array(new bar_stack_key('#C4D318', 'used', 13), new bar_stack_key('#7D7B6A', 'total', 13))); $bar_stack->set_on_click('(function(x){var services=' . json_encode($services) . ';alert(services[x]);})'); //js $bar_stack->set_tooltip('#val#M,共#total#M'); $y = new y_axis(); $y->set_range(0, $max + 32, 256); $x = new x_axis(); $x->set_labels_from_array($lables); $tooltip = new tooltip(); $tooltip->set_hover(); $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($bar_stack); $chart->set_x_axis($x); $chart->add_y_axis($y); $chart->set_tooltip($tooltip); return $chart->toPrettyString(); }
function generateStats($params) { global $reportCacheLocation; // Computer Statistics Generation $dbTrackHandler = connectDb(); $resultBag = generateStatsBag($params, $dbTrackHandler); // ---------------------------------------------------- // Generate charts $animation_1 = isset($params['animation_1']) ? $params['animation_1'] : 'pop'; $delay_1 = isset($params['delay_1']) ? $params['delay_1'] : 0.5; $cascade_1 = isset($params['cascade_1']) ? $params['cascade_1'] : 1; $title = new title("Genie Report: " . $params['reportName'] . " - Generated on " . date('Y/m/d h:i:s A')); $title->set_style("{font-size: 12px; color: #000000; text-align: center;}"); $bar_stack = new bar_stack(); if ($params['reportType'] == 'computerStats') { foreach ($resultBag as $elm) { $tmpTotal = $elm[AVAIBILITY_TYPE_OFFLINE] + $elm[AVAIBILITY_TYPE_AVAILABLE] + $elm[AVAIBILITY_TYPE_BUSY]; if ($tmpTotal == 0) { $tmpTotal = 1; } // Only Chuck Norris can divide by Zero. $bar_stack->append_stack(array($elm[AVAIBILITY_TYPE_OFFLINE] / $tmpTotal * 100, $elm[AVAIBILITY_TYPE_AVAILABLE] / $tmpTotal * 100, $elm[AVAIBILITY_TYPE_BUSY] / $tmpTotal * 100)); } $bar_stack->set_colours(array('#FF0000', '#00FF00', '#A25B00')); $bar_stack->set_keys(array(new bar_stack_key('#FF0000', 'OFFLINE', 13), new bar_stack_key('#00FF00', 'FREE', 13), new bar_stack_key('#A25B00', 'BUSY', 13))); } else { $allProgNames = array(); foreach ($resultBag as $elm) { $progNames = array_keys($elm); foreach ($progNames as $progName) { if (validProgram($progName)) { if (!array_key_exists($progName, $allProgNames)) { $allProgNames[$progName] = "#" . dechex(rand(0, 10000000)); } } } } $progsArray = array(); foreach ($resultBag as $elm) { $tmpTotal = 0; $progNames = array_keys($elm); foreach ($elm as $programName => $programWeight) { if (validProgram($programName)) { $tmpTotal += $programWeight; } } //echo "<h1>$tmpTotal</h1>"; if ($tmpTotal == 0) { $tmpTotal = 1; } // Only Chuck Norris can divide by Zero. $progs = array(); foreach ($elm as $programName => $programWeight) { if (validProgram($programName)) { $percentVal = $programWeight / $tmpTotal * 100; $progs[] = new bar_stack_value($percentVal, $allProgNames[$programName]); $progsArray[$percentVal * 1000000] = $programName; } } $bar_stack->append_stack($progs); } $legends = array(); //$strAllProgNames = array_keys($allProgNames); foreach ($allProgNames as $programName => $programColor) { $legends[] = new bar_stack_key($programColor, $programName, 13); } $bar_stack->set_keys($legends); ksort($progsArray); echo "<pre>"; while (list($key, $value) = each($progsArray)) { $kw = $key / 1000000; echo "{$kw}: {$value}<br />\n"; } echo "</pre>"; } //$bar_stack->set_tooltip( 'In #x_label# you get #total# days holiday a year.<br>Number of days: #val#' ); $bar_stack->set_on_show(new bar_on_show($animation_1, $cascade_1, $delay_1)); $y = new y_axis(); $y->set_range(0, 100, 10); //$y->set_range( 0, $tmpMax, $tmpMax/10 ); $x_labels = new x_axis_labels(); $x_labels->rotate(45); $x_labels->set_labels(array_keys($resultBag)); $x = new x_axis(); $x->set_labels($x_labels); $tooltip = new tooltip(); $tooltip->set_hover(); $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($bar_stack); $chart->set_x_axis($x); $chart->add_y_axis($y); $chart->set_tooltip($tooltip); // ---------------------------------------------------- $cacheid = time(); $filename = $cacheid . '.cache.json'; $myFile = "{$reportCacheLocation}/reports-cache/" . $filename; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $chart->toPrettyString()); fclose($fh); return $cacheid; }