public static function create_area_graph($title) { self::init(); $d = new solid_dot(); $d->size(3)->halo_size(1)->colour('#3D5C56'); $range_values = array(); foreach (self::$data_set as $data) { if (!is_array($data['values'])) { continue; } $area = new area(); // set the circle line width: $area->set_width(2); $area->set_default_dot_style($d); $area->set_colour($data['color']); $area->set_fill_colour($data['color']); $area->set_fill_alpha(0.3); $area->on_show(new line_on_show('pop-up', 2, 0.5)); $area->set_key($data['line_title'], 10); $area->set_values($data['values']); # Since there should be an even number on the xaxis for all sets $x_axis_titles = $data['titles']; # Add our values into a big bucket so we can get the highest and lowest $range_values = array_merge($range_values, $data['values']); self::$chart->add_element($area); } $x_labels = new x_axis_labels(); $x_labels->set_labels($x_axis_titles); $x_labels->set_vertical(); self::$x_axis->set_labels($x_labels); $range = self::get_range($range_values); self::$y_axis->set_range($range['min'], $range['max']); self::show_chart($title); }
/** * Creates a preconfigured area element (colors etc.) * */ protected function createArea($color = '#f58615', $fill_color = '#fcdeba') { $dot = $this->createDot($color); $area = new area(); // set the circle line width: $area->set_width(2); $area->set_default_dot_style($dot); $area->set_colour($color); $area->set_fill_colour($fill_color); $area->set_fill_alpha(0.8); return $area; }
/** * 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; }
$data = array(); for ($i = 0; $i < 6.2; $i += 0.2) { $tmp = sin($i) * 1.9; $data[] = $tmp; } include '../php-ofc-library/open-flash-chart.php'; $chart = new open_flash_chart(); $chart->set_title(new title('Area Chart')); // // Make our area chart: // $area = new area(); // set the circle line width: $area->set_width(2); $area->set_default_dot_style(new hollow_dot()); $area->set_colour('#838A96'); $area->set_fill_colour('#E01B49'); $area->set_fill_alpha(0.4); $area->set_values($data); // add the area object to the chart: $chart->add_element($area); $y_axis = new y_axis(); $y_axis->set_range(-2, 2, 2); $y_axis->labels = null; $y_axis->set_offset(false); $x_axis = new x_axis(); $x_axis->labels = $data; $x_axis->set_steps(2); $x_labels = new x_axis_labels(); $x_labels->set_steps(4);
$line_max_default_dot = new dot(); $line_max_default_dot->size(3)->halo_size(2)->colour('#3D5C56'); */ /* $line_max = new line(); $line_max->set_default_dot_style($line_max_default_dot); $line_max->set_values( $data_max ); $line_max->set_colour( '#FEE88F' ); $line_max->set_width( 1 ); $line_max->set_key( 'Max (W)', 10 ); $line_max->set_tooltip( "#val# W" ); */ $line_watt_default_dot = new dot(); $line_watt_default_dot->size(4)->colour('#f00000'); $line_watt = new area(); $line_watt->set_default_dot_style($line_watt_default_dot); $line_watt->set_values($data_watt); $line_watt->set_colour('#4D4D4D'); $line_watt->set_fill_colour('#EFC01D'); $line_watt->set_fill_alpha(0.75); $line_watt->set_width(2); $line_watt->set_key('Leistung (W)', 10); $line_watt->set_tooltip("#val# W"); $line_tot_default_dot = new dot(); $line_tot_default_dot->size(4)->halo_size(2); $line_tot = new line(); $line_tot->set_default_dot_style($line_tot_default_dot); $line_tot->set_values($data_tot); $line_tot->set_colour('#A0A000'); $line_tot->set_width(2); $line_tot->set_key('Gesamt (kWh)', 10);
public function get_jx_json($info, $type = '') { $year = array_keys($info); $price = array_values($info); $chart = new open_flash_chart(); $chart->set_bg_colour('#FFFFFF'); //flash背景颜色 //$title = new title( 'UK Petrol price (pence) per Litre' ); //$title->set_style( "{font-size: 20px; color: #A2ACBA; text-align: center;}" ); //$chart->set_title( $title ); $d = new hollow_dot(); $d->size(3)->halo_size(0)->colour('#8f8fbd'); $area = new area(); $area->set_width(2); $area->set_default_dot_style($d); $area->set_fill_colour('#eaf6ff'); $area->set_fill_alpha(0.4); $area->set_colour('#8f8fbd'); //$area->set_values($price); $area->set_values($price); $chart->add_element($area); $num = intval(count($year >= 7 ? $year : 7) / 7); if ($num == 0) { $num = intval(count($year)); } $num = $num > 0 ? $num : 1; $x_labels = new x_axis_labels(); $x_labels->set_steps($num); $x_labels->set_size(12); $x_labels->set_colour('#000000'); $x_labels->set_labels($year); if (count($year) > 0) { $x_labels->set_vertical(); } // // 插入数据 $x = new x_axis(); $x->set_colour('#000000'); $x->set_grid_colour('#dadada'); $x->set_offset(false); $x->set_steps($num); // Add the X Axis Labels to the X Axis //$x->set_labels($x_labels); $x->set_labels_from_array($year); $chart->set_x_axis($x); $y = new y_axis(); $y->labels = null; $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; }
if ($ok) { while ($row = mysql_fetch_object($ok)) { $data_w[$row->m] = round((double) $row->Watt, 3); $data_t[$row->m] = round((double) $row->ETotal, 3); } $title = new title("\nJahresueberblick Verteilung"); $title->set_style('{font-size: 20px; color: #778877}'); $vals = array(); for ($i = 0; $i < count($data_w); $i++) { $tmp = new solid_dot($data_t[$i]); $tmp->colour('#4d4d4d')->tooltip("{$time_axis[$i]}<br>#val# kWh"); $vals[] = $tmp; } $area_w = new area(); $area_w->set_width(1); $area_w->set_default_dot_style(new hollow_dot('#EFC01D', 5)); $area_w->set_colour('#EFC01D'); $area_w->set_fill_colour('#EFC01D'); $area_w->set_fill_alpha(0.4); $area_w->set_loop(); $area_w->set_values($vals); $line_t = new line(); $line_t->set_values($data_t); $max = max($data_t) * 1.15; $label = array(); for ($i = 0; $i < $max; $i = $i + round($max * 0.1, -1)) { $label[] = $i; } $r = new radar_axis($max); $r->set_colour('#EFD1EF'); $r->set_steps(round($max * 0.1, -1));
//foreach //var_dump($y_data); foreach ($y_data as $key => $data) { $line_dot = new area(); //$line_dot = new line(); if (isset($channels[$key])) { $legend = $channels[$key]['name'] . ':(' . end($data) . ')'; $color = $channels[$key]['color']; $line_dot->set_width(1); } else { $legend = 'Total:(' . end($data) . "/{$total_avg}/{$total_max})"; $color = '#e81dd7'; $line_dot->set_width(3); } $line_dot->set_values($data); $line_dot->set_default_dot_style($hol); $line_dot->set_fill_colour($color); $line_dot->set_fill_alpha(0.05); $line_dot->set_colour($color); $line_dot->set_key($legend, 10); $chart->add_element($line_dot); $line_dot = NULL; } $y = new y_axis(); // grid steps: $y->set_range(0, $max_val + 10, (int) (($max_val + 10) / 10)); /*$y_labels = new y_axis_labels(); $y_labels->set_size (15); $y->set_labels( $y_labels );*/ $chart->set_y_axis($y); $x = new x_axis();
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 }