/** * 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(); }
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; }
$line->set_colour('#668053'); $chart->add_element($line); // title properties $portfolio_type = array("", "Unknown", "401(k)", "Traditional IRA", "Roth IRA", "SIMPLE IRA", "SEP-IRA", "Solo 401(k)", "Roth 401(k)", "403(b)", "Other"); $type_idx = $_GET['i']; $type_idx = $type_idx == 0 ? $type_idx : $type_idx - 1; $title = new title("Individual Portfolio Performance (" . $portfolio_type[$type_idx] . ")"); $title->set_style("{font-size: 25px; font-family: Calibri; font-weight: bold; color: #121212; text-align: center;}"); $chart->set_title($title); // y axis properties $y = new y_axis(); $y_min = 0.0; $y_max = 0.0; $y_min = floor(0.995 * $amt_min); $y_max = ceil(1.005 * $amt_max); $y->set_grid_colour('#EFEFEF'); $y->set_range($y_min, $y_max, round(($y_max - $y_min) / 5.0)); $chart->set_y_axis($y); // y legend properties $y_legend = new y_legend('Amount ($)'); $y_legend->set_style('{font-size:15px; font-family:Calibri; color:#121212}'); $chart->set_y_legend($y_legend); // x axis properties $x = new x_axis(); $x->set_labels_from_array($x_labels); $x->grid_colour('#EFEFEF'); $chart->set_x_axis($x); // background properties $chart->set_bg_colour('#FFFFFF'); // menu $m = new ofc_menu("#E0E0FF", "#707070");
$candle = new candle('#134871'); //9933CC $candle->set_values($data); $candle->set_tooltip('#x_label#<br>High: #high#<br>Open: #open#<br>Close: #close#<br>Low: #low#'); $y = new y_axis(); $range = $highest - $lowest; if ($range < 15) { $y->set_range(round($lowest - 1), round($highest + 1), 1); } else { if ($range < 100) { $y->set_range(round($lowest - 1), round($highest + 1), 5); } else { $y->set_range(round($lowest - 10, -1), round($highest + 10, -1), 10); } } $y->set_grid_colour("#E3E3E3"); $chart = new open_flash_chart(); $chart->set_bg_colour("#FCFCFC"); $chart->set_title($title); $chart->add_element($candle); if ($sma_50 == 1) { $chart->add_element($line_sma50); } if ($sma_25 == 1) { $chart->add_element($line_sma25); } if ($sma_15 == 1) { $chart->add_element($line_sma15); } if ($sma_10 == 1) { $chart->add_element($line_sma10);
$bar = new bar_glass(55, '#D54C78', '#C31812'); include_once 'db.php'; $q = mysql_query("select count(c_browser) as tot from tracker where c_id=1234 and c_browser='" . $br . "' and " . $dateRange); $bar->set_values(array(1245, 1202, 455, 120, 3652, 454, 121, 452, 1023, 1054, 1500, 1245, 1278, 123, 6598, 6547, 6589, 6999, 7854, 7562, 5478, 1200, 1254, 1562, 5415, 2587, 4589)); $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($bar); $x = new x_axis(); $x->set_range(0, 31, 1); $chart->set_x_axis($x); $chart->set_y_axis($x); $y = new y_axis(); $y->set_stroke(3); $y->set_colour('#000000'); $y->set_tick_length(7); $y->set_grid_colour('#000000'); // grid steps: $y->set_range(0, 10000, 1000); //$y_labels = new y_axis_labels(); //$y_labels->set_labels( array('Zero','One','Two','Three','Four','Five','Six','Seven','Eight') ); // visible labels steps: //$y_labels->set_steps(4); //$y->set_labels($y_labels); // // Add the Y Axis object to the chart: // $chart->set_y_axis($y); $chart->set_bg_colour('#FFFFCC'); // // This is the VIEW section: //
function get_graph($field, $args) { $defaults = array('ids' => false, 'colors' => array('#EF8C08', '#21759B', '#1C9E05'), 'grid_color' => '#f7e8bf', 'bg_color' => '#FFFFFF', 'odd' => false, 'truncate' => 40, 'truncate_label' => 15, 'response_count' => 10, 'user_id' => false, 'type' => 'default', 'x_axis' => false, 'data_type' => 'count', 'limit' => '', 'x_start' => '', 'x_end' => '', 'show_key' => false, 'min' => '', 'max' => '', 'include_zero' => false, 'width' => 400, 'height' => 400); $args = wp_parse_args($args, $defaults); $vals = $this->get_graph_values($field, $args); extract($args); extract($vals); $title = new title(preg_replace("/&#?[a-z0-9]{2,8};/i", "", FrmAppHelper::truncate($field->name, $truncate, 0))); $chart = new open_flash_chart(); $chart->set_title($title); $bar = new bar_glass(); $x = new x_axis(); $y = new y_axis(); $x_labels = new x_axis_labels(); if (in_array($field->type, array('select', 'checkbox', 'radio', '10radio', 'scale')) and (!isset($x_inputs) or !$x_inputs)) { $x_labels->rotate(340); //$x_labels->set_colour( '#A2ACBA' ); //$x->set_colour( '#A2ACBA' ); } else { if ($field->type == 'user_id') { if (!$pie) { $x_labels->rotate(340); } } else { $x_labels->rotate(340); } } $pie = $type == 'default' ? $pie : ($type == 'pie' ? true : false); if ($pie) { $bar = new pie(); $bar->set_alpha(0.6); $bar->set_start_angle(35); $bar->add_animation(new pie_fade()); $bar->set_tooltip('#val# (#percent#)'); $bar->set_colours($colors); $pie_values = array(); foreach ($values as $val_key => $val) { if ($val) { $pie_values[] = new pie_value($val, "{$labels[$val_key]} (" . round($val / $total_count * 100) . "%)"); } } $bar->set_values($pie_values); } else { $color = $odd ? current($colors) : next($colors); if (!$color) { $color = reset($colors); } if ($type == 'line') { $bar = new line(); } else { if ($type == 'hbar') { $bar = new hbar($color); } else { if ($type == 'area') { $bar = new area(); } else { if ($type == 'bar_flat') { $bar = new bar($color); } else { $bar = new bar_glass($color); } } } } $bar->set_colour($color); $bar->set_values($values); if ($show_key) { $bar->set_key(stripslashes($field->name), $show_key); } $x_labels->set_labels($labels); $x->set_labels($x_labels); $x->set_grid_colour($grid_color); $y->set_grid_colour($grid_color); if ($combine_dates and !strpos($width, '%') and count($labels) * 30 > (int) $width) { $x_labels->visible_steps(ceil(count($labels) * 30 / (int) $width)); } $set_max = $max; if (!empty($values) and empty($max)) { $max = abs(max($values) * 1.2); if ($max < 3) { $max = 3; } } foreach ($ids as $f_id) { $new_max = abs(max($f_values[$f_id]) * 1.2); if ($set_max != $max and $new_max > $max) { $max = $new_max; } unset($f_id); unset($new_max); } $bars = array(); foreach ($f_values as $f_id => $f_vals) { if ($type == 'line') { $bars[$f_id] = new line(); } else { if ($type == 'hbar') { $bars[$f_id] = new hbar($color); } else { if ($type == 'area') { $bars[$f_id] = new area(); } else { if ($type == 'bar_flat') { $bars[$f_id] = new bar(); } else { $bars[$f_id] = new bar_glass(); } } } } $color = next($colors); if (!$color) { $color = reset($colors); } $bars[$f_id]->set_colour($color); $bars[$f_id]->set_values($f_vals); if ($show_key) { $bars[$f_id]->set_key(stripslashes($fields[$f_id]->name), $show_key); } unset($f_id); } if (isset($max) and !empty($max)) { $step = ceil($max / 10); if (empty($min)) { $min = 0; } $y->set_range($min, $max, $step); } } $chart->add_element($bar); if (isset($bars) and !empty($bars)) { foreach ($bars as $f_bar) { $chart->add_element($f_bar); } } $chart->set_bg_colour($bg_color); if (!$pie) { $chart->set_y_axis($y); $chart->set_x_axis($x); } return $chart->toPrettyString(); }
function get_linear_graph($dates, $vals, $keys = array()) { include 'php-ofc-library/open-flash-chart.php'; $max_y = 0; $arr_filled = array(); for ($i = 0; $i < count($dates); $i++) { $year[] = $dates[$i]; for ($m = 0; $m < count($vals); $m++) { $price[$m][] = (int) $vals[$m][$i]; if ($max_y < (int) $vals[$m][$i]) { $max_y = (int) $vals[$m][$i]; } if (@$arr_filled[$m] != $vals[$m][$i] and @$arr_filled[$m] == 0) { @($arr_filled[$m] = (int) $vals[$m][$i]); } } } while ($max_y % 10 != 0) { $max_y++; } $chart = new open_flash_chart(); //$title = new title( 'UK Petrol price (pence) per Litre' ); $d = new anchor(); if (count($dates) > 60) { $d->size(2); } else { $d->size(3); } $d->halo_size(1); $d->colour('#3D5C56'); $d->rotation(0); $d->sides(4); for ($i = 0; $i < count($price); $i++) { if ($arr_filled[$i] == 0) { continue; } if ($i == 0) { $color = '#5E0722'; } elseif ($i == 1) { $color = '#00FF00'; } else { $color = '#FF0000'; } $area = new area(); $area->set_colour($color); $area->set_default_dot_style($d); $area->set_values($price[$i]); if (isset($keys[$i])) { $area->set_key($keys[$i], 12); } // mb_convert_encoding($keys[$i], "UTF-8", "Windows-1251") $area->set_width(2); $chart->add_element($area); } $x_labels = new x_axis_labels(); if (count($dates) > 40) { $x_labels->set_steps(7); } else { $x_labels->set_steps(1); } $x_labels->set_vertical(); $x_labels->set_colour('#000000'); $x_labels->set_labels($year); $x_labels->rotate(-55); $x_labels->set_size(12); $x = new x_axis(); $x->set_colour('#000000'); $x->set_grid_colour('#DDDDDD'); //$x->set_offset( false ); $x->set_steps(1); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $chart->set_x_axis($x); $y = new y_axis(); $y->set_range(0, $max_y); $y->set_colour('#000000'); $y->set_grid_colour('#DDDDDD'); $chart->add_y_axis($y); $chart->set_bg_colour("#FFFFFF"); ?> <script type="text/javascript" src="script/json/json2.js"></script> <script type="text/javascript" src="script/swfobject.js"></script> <script type="text/javascript"> swfobject.embedSWF("open-flash-chart.swf", "my_chart", "600", "350", "9.0.0"); </script> <script type="text/javascript"> function ofc_ready() { } function open_flash_chart_data() { return JSON.stringify(data); } function findSWF(movieName) { if (navigator.appName.indexOf("Microsoft")!= -1) { return window[movieName]; } else { return document[movieName]; } } var data = <?php echo $chart->toPrettyString(); ?> ; </script> <?php }