function graficoBarra($data, $archivo = "", $meta_data = array('titulo' => 'Sin Título', 'tituloX' => 'Eje X', 'tituloY' => 'Eje Y', 'color' => 'SkyBlue', 'width' => 800, 'height' => 600, 'angle' => 45), $legend = array("Datos")) { # Objeto que crea el gráfico y su tama?o $plot = new PHPlot($meta_data['width'], $meta_data['height']); $plot->SetImageBorderType('plain'); # Setea el archivo donde se guarda la imagen generada y no permite la visualización inmediata $plot->SetPrintImage(false); $plot->SetFileFormat("jpg"); $plot->SetOutputFile($archivo); $plot->SetIsInline(true); # Envio de datos $plot->SetDataValues($data); # Tipo de gráfico y datos $plot->SetDataType("text-data"); $plot->SetPlotType("bars"); # Setiando el True type font //$plot->SetTTFPath(TTFPath); //$plot->SetUseTTF(TRUE); $plot->SetAxisFontSize(2); $plot->SetVertTickIncrement(7); //$plot->SetXTickLength(7); //$plot->SetDataColors($meta_data['color']); $plot->SetDataColors(array($meta_data['color'], 'red', 'white')); $plot->SetLegendPixels(1, 1); $plot->SetLegend($legend); # Etiquetas del eje Y: $plot->SetYTitle($meta_data['tituloY']); $plot->SetYDataLabelPos('plotin'); # Título principal del gráfico: $plot->SetTitle($meta_data['titulo']); # Etiquetas eje X: $plot->SetXTitle($meta_data['tituloX']); if (isset($meta_data['angle'])) { $plot->SetXLabelAngle($meta_data['angle']); } else { $plot->SetXLabelAngle(45); } $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); # Método que dibuja el gráfico $plot->DrawGraph(); $plot->PrintImage(); }
$p->SetDataValues($data); # Fix Y ticks $p->SetPlotAreaWorld(NULL, 0, NULL, NULL); $p->SetYTickIncrement(5); # Font: if ($tp['TTF']) { # Using TrueType fonts: Set path and default font. $p->SetTTFPath($phplot_test_ttfdir); $font = $phplot_test_ttfonts[$tp['FontName']]; $p->SetDefaultTTFont($font); # Now select label font with size (if supplied): if (empty($tp['FontSize'])) { $p->SetFont('x_label', $font); } else { $p->SetFont('x_label', $font, $tp['FontSize']); } } else { # Using GD fonts: if (isset($tp['FontSize'])) { $p->SetFont('x_label', $tp['FontSize']); } } # Label angle: if (isset($tp['angle'])) { $p->SetXLabelAngle($tp['angle']); } # Turn off X tick labels and ticks because they don't apply here: $p->SetXTickLabelPos('none'); $p->SetXTickPos('none'); $p->SetPlotType('bars'); $p->DrawGraph();
$result = mysql_query("SELECT Max(player_money_total_amount) max,min(player_money_total_amount) min FROM meridian103.player_money_total;"); while ($row = mysql_fetch_assoc($result)) { $max = $row['max']; $min = $row['min']; } $min -= 1000000; mysql_free_result($result); */ $result = mysql_query("SELECT player_money_total_amount amount, player_money_total_time time from meridian103.player_money_total where date(player_money_total_time) = date(now()) order by player_money_total_time ASC;"); while ($row = mysql_fetch_assoc($result)) { $data[] = array($row['time'], $row['amount']); } mysql_free_result($result); mysql_close($link); //Define the object $plot = new PHPlot(); $plot->SetTitle("Server 103 Total Shillings over Time - Period 1 Day"); $plot->SetFontGD('y_label', 5); $plot->SetFontGD('x_label', 5); //$plot->SetPlotAreaWorld(NULL,$min,NULL,$max); $plot->SetXLabelAngle(90); $plot->SetYDataLabelPos('plotin'); $plot->SetDrawYDataLabelLines('false'); //$plot->SetFontGD('y_title', 5); //$plot->SetFontGD('x_title', 5); $plot->SetDataValues($data); //Turn off X axis ticks and labels because they get in the way: $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); //Draw it $plot->DrawGraph();
} if ($debug) { print_r($allDays); } if ($debug) { print "I" . $maxValue . "I"; } include "../include/phplot/phplot.php"; $graph = new PHPlot(600, 300); $graph->SetDataType("text-data"); $graph->SetDataValues($allDays); $graph->SetYTickIncrement(); $graph->y_tick_increment = ceil(@$graph->y_tick_increment); $graph->SetXLabelType("time"); $graph->SetXTimeFormat("%b %d"); if ($incoming == '2') { $graph->SetLegend(array("Outgoing")); $graph->SetDataColors(array('green')); } elseif ($incoming == '3') { $graph->SetLegend(array("Incoming")); $graph->SetDataColors(array('orange')); } else { $graph->SetLegend(array("All", "Outgoing", "Incoming")); } $graph->SetYTitle("Quantity of calls"); $graph->SetPlotType("bars"); $graph->SetXLabelAngle(90); // Turn off X tick labels and ticks because they don't apply here: $graph->SetXTickLabelPos('none'); $graph->SetXTickPos('none'); $graph->DrawGraph();
$graph->SetDrawYGrid(TRUE); break; case 'both': $graph->SetDrawXGrid(TRUE); $graph->SetDrawYGrid(TRUE); break; case 'none': $graph->SetDrawXGrid(FALSE); $graph->SetDrawYGrid(FALSE); } $graph->SetXTickLabelPos($which_xtick_label_pos); $graph->SetYTickLabelPos($which_ytick_label_pos); $graph->SetXDataLabelPos($which_xdata_label_pos); $graph->SetYDataLabelPos($which_ydata_label_pos); // Please remember that angles other than 90 are taken as 0 when working fith fixed fonts. $graph->SetXLabelAngle($which_xlabel_angle); $graph->SetYLabelAngle($which_ylabel_angle); //$graph->SetLineStyles(array("dashed","dashed","solid","solid")); $graph->SetPointShape($which_point); $graph->SetPointSize($which_point_size); $graph->SetDrawBrokenLines($which_broken); // Some forms in format_chart.php don't set this variable, suppress errors. @$graph->SetErrorBarShape($which_error_type); $graph->SetXAxisPosition($which_xap); $graph->SetYAxisPosition($which_yap); $graph->SetPlotBorderType($which_btype); if ($maxy_in) { if ($which_data_type = "text-data") { $graph->SetPlotAreaWorld(0, $miny_in, count($data), $maxy_in); } }
function guifi_stats_chart05($nmonths) { include drupal_get_path('module', 'guifi') . '/contrib/phplot/phplot.php'; $gDirTTFfonts = drupal_get_path('module', 'guifi') . '/contrib/fonts/'; if (isset($_GET['width'])) { $gwidth = $_GET['width']; } else { $gwidth = 500; } if (isset($_GET['height'])) { $gheight = $_GET['height']; } else { $gheight = 450; } if (isset($_GET['zone'])) { $zone_id = $_GET['zone']; if ($zone_id == "3671") { $zone_id = "0"; } } else { $zone_id = "0"; } $vsql = "select COUNT(*) as num, MONTH(FROM_UNIXTIME(timestamp_created)) as mes, YEAR(FROM_UNIXTIME(timestamp_created)) as ano \n from {guifi_location}\n where status_flag='Working' "; if ($zone_id != "0") { $achilds = guifi_zone_childs($zone_id); $v = ""; foreach ($achilds as $key => $child) { if ($v == "") { $v .= "zone_id=" . $child; } else { $v .= " or zone_id=" . $child; } } $vsql .= "AND (" . $v . ") "; } $vsql .= "GROUP BY YEAR(FROM_UNIXTIME(timestamp_created)),MONTH(FROM_UNIXTIME(timestamp_created)) "; $result = db_query($vsql); $inicial = 5; $nreg = $inicial; $tot = 0; $ano = 2004; $mes = 5; $items = 2004; $label = "a"; $n = 0; $med = 0; $datos = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); $today = getdate(); if ($nmonths == 0) { $nmonths = 12; } $max = 0; while ($record = db_fetch_object($result)) { if ($record->ano >= 2004) { if ($mes == 12) { $mes = 1; $ano++; } else { $mes++; } if ($ano == $today[year] && $mes >= $today[mon]) { if ($mes == 1) { $mes = 12; $ano--; } else { $mes--; } break; } while ($ano < $record->ano || $mes < $record->mes) { $nreg++; if ($mes == 6) { $label = $ano; } else { $label = ''; } if ($n == 0) { $tot += $record->num; } else { $tot = $record->num; } $tot2 = fmediacalc($tot, $datos, $n, $nmonths); $data[] = array("{$label}", $nreg, $tot2); if (floor($tot2) > $max) { $max = floor($tot2); } if ($mes == 12) { $mes = 1; $ano++; } else { $mes++; } } $tot += $record->num; $nreg++; if ($mes == 6) { $label = $ano; } else { $label = ''; } if ($n == 0) { $tot += $record->num; } else { $tot = $record->num; } $tot2 = fmediacalc($tot, $datos, $n, $nmonths); $data[] = array("{$label}", $nreg, $tot2); if (floor($tot2) > $max) { $max = floor($tot2); } } else { $tot += $record->num; } } while ($mes < 12) { $nreg++; $mes++; if ($mes == 6) { $label = $ano; } else { $label = ''; } $data[] = array("{$label}", $nreg, ""); } if ($tot <= 10) { $inc = 1; } else { $vlen = strlen($max); $vini = substr($max, 0, 1); $inc = str_pad($vini, $vlen - 1, "0"); } $items = ($ano - $items + 1) * 12; $shapes = array('none'); $plot = new PHPlot($gwidth, $gheight); $plot->SetPlotAreaWorld(0, 0, $items, NULL); $plot->SetFileFormat('png'); $plot->SetDataType("data-data"); $plot->SetDataValues($data); $plot->SetPlotType("linepoints"); $plot->SetYTickIncrement($inc); $plot->SetXTickIncrement(12); $plot->SetSkipBottomTick(TRUE); $plot->SetSkipLeftTick(TRUE); $plot->SetXAxisPosition(0); $plot->SetPointShapes($shapes); $plot->SetPointSizes(10); $plot->SetTickLength(3); $plot->SetDrawXGrid(TRUE); $plot->SetTickColor('grey'); $plot->SetTTFPath($gDirTTFfonts); $plot->SetFontTTF('title', 'Vera.ttf', 12); if (isset($_GET['title'])) { $plot->SetTitle("guifi.net \n" . t($_GET['title'])); } else { if ($zone_id == "0") { $plot->SetTitle("guifi.net \n" . t('Nodes per month, ' . "{$nmonths}" . ' months average')); } else { $plot->SetTitle("guifi.net " . t('zone') . ": " . guifi_get_zone_name($zone_id) . "\n" . t('Nodes per month, ' . "{$nmonths}" . ' months average')); } } $plot->SetXTitle(t('Years')); $plot->SetYTitle(t('Working nodes')); $plot->SetDrawXDataLabelLines(FALSE); $plot->SetXLabelAngle(0); $plot->SetXLabelType('custom', 'guifi_stats_chart05_LabelFormat'); $plot->SetGridColor('red'); $plot->SetPlotBorderType('left'); $plot->SetDataColors(array('orange')); $plot->SetTextColor('DimGrey'); $plot->SetTitleColor('DimGrey'); $plot->SetLightGridColor('grey'); $plot->SetBackgroundColor('white'); $plot->SetTransparentColor('white'); $plot->SetXTickLabelPos('none'); $plot->SetXDataLabelPos('plotdown'); $plot->SetIsInline(TRUE); $plot->DrawGraph(); }
$range = "{$xmin} : {$xmax}"; } $title = "Date/time X Auto-Range Test: [{$range}]"; if (isset($mintick)) { $title .= "\nX Min Ticks = {$mintick}"; } if (isset($xtickinc)) { $title .= "\nX Tick Increment = {$xtickinc}"; } if (isset($tickanchor)) { $title .= "\nX Tick Anchor = {$tickanchor}"; } $p = new PHPlot(800, 800); $p->SetTitle($title); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetXDataLabelPos('none'); $p->SetPlotType('lines'); # Format labels as date/time: $p->SetXLabelType('time', $dtformat); $p->SetXLabelAngle(90); if (isset($mintick)) { $p->TuneXAutoTicks($mintick); } if (isset($tickanchor)) { $p->SetXTickAnchor($tickanchor); } if (isset($xtickinc)) { $p->SetXTickIncrement($xtickinc); } $p->DrawGraph();
$p->SetFont('y_title', '', 12); $p->SetFont('x_label', '', 12); $p->SetFont('y_label', '', 12); $p->SetFont('generic', '', 14); } elseif ($tp['use_gdf']) { $p->SetFont('legend', '4'); $p->SetFont('title', '5'); $p->SetFont('x_title', '3'); $p->SetFont('y_title', '3'); $p->SetFont('x_label', '2'); $p->SetFont('y_label', '2'); $p->SetFont('generic', '2'); } # All axis, all labels, both sides $p->SetTitle($tp['title'] . $tp['suffix']); $p->SetLegend(array('Legend 1', 'Legend 2', 'Legend 3')); $p->SetXTitle('X Axis Title Here', 'both'); $p->SetYTitle('Y Axis Title Here', 'both'); $p->SetXTickLabelPos('none'); $p->SetXTickPos('none'); $p->SetXDataLabelPos('both'); $p->SetYTickLabelPos('both'); $p->SetYTickPos('both'); $p->SetYDataLabelPos('plotin'); if (isset($tp['x_label_angle'])) { $p->SetXLabelAngle($tp['x_label_angle']); } if (isset($tp['y_label_angle'])) { $p->SetYLabelAngle($tp['y_label_angle']); } $p->DrawGraph();
function plot_guifi() { include drupal_get_path('module', 'guifi') . '/contrib/phplot/phplot.php'; $result = db_query("select COUNT(*) as num, MONTH(FROM_UNIXTIME(timestamp_created)) as mes, YEAR(FROM_UNIXTIME(timestamp_created)) as ano from {guifi_location} where status_flag='Working' GROUP BY YEAR(FROM_UNIXTIME(timestamp_created)),MONTH(FROM_UNIXTIME(timestamp_created)) "); $inicial = 5; $nreg = $inicial; $tot = 0; $ano = 2004; $mes = 5; $items = 2004; $label = ""; while ($record = db_fetch_object($result)) { if ($record->ano >= 2004) { if ($mes == 12) { $mes = 1; $ano++; } else { $mes++; } while ($ano < $record->ano || $mes < $record->mes) { $nreg++; if ($mes == 6) { $label = $ano; } else { $label = ''; } $data[] = array("{$label}", $nreg, $tot, ''); if ($mes == 12) { $mes = 1; $ano++; } else { $mes++; } } $tot += $record->num; $nreg++; if ($mes == 6) { $label = $ano; } else { $label = ''; } $data[] = array("{$label}", $nreg, $tot, ''); } else { $tot += $record->num; } } while ($mes < 12) { $nreg++; $mes++; if ($mes == 6) { $label = $ano; } else { $label = ''; } $data[] = array("{$label}", $nreg, ""); } $items = ($ano - $items + 1) * 12; if ($tot % 1000 < 30) { $data[$nreg - $inicial - 1][3] = $tot; $vt = floor($tot / 1000) * 1000; $vtitle = $vt . " " . t('Nodes') . "!!!"; $tcolor = 'red'; } else { $vtitle = t('Working nodes'); $tcolor = 'DimGrey'; } $shapes = array('none', 'circle'); $plot = new PHPlot(200, 150); $plot->SetPlotAreaWorld(0, 0, $items, NULL); $plot->SetFileFormat('png'); $plot->SetDataType("data-data"); $plot->SetDataValues($data); $plot->SetPlotType("linepoints"); $plot->SetYTickIncrement(2000); $plot->SetXTickIncrement(12); $plot->SetSkipBottomTick(TRUE); $plot->SetSkipLeftTick(TRUE); $plot->SetXAxisPosition(0); $plot->SetPointShapes($shapes); $plot->SetPointSizes(10); $plot->SetTickLength(3); $plot->SetDrawXGrid(TRUE); $plot->SetTickColor('grey'); $plot->SetTitle($vtitle); $plot->SetDrawXDataLabelLines(FALSE); $plot->SetXLabelAngle(0); $plot->SetXLabelType('custom', 'Plot1_LabelFormat'); $plot->SetGridColor('red'); $plot->SetPlotBorderType('left'); $plot->SetDataColors(array('orange')); $plot->SetTextColor('DimGrey'); $plot->SetTitleColor($tcolor); $plot->SetLightGridColor('grey'); $plot->SetBackgroundColor('white'); $plot->SetTransparentColor('white'); $plot->SetXTickLabelPos('none'); $plot->SetXDataLabelPos('plotdown'); $plot->SetIsInline(TRUE); $plot->DrawGraph(); }
/** * Adds raw image data of the graph to the output. * @param $opts FormOptions */ public function draw( FormOptions $opts ) { global $wgTranslatePHPlotFont, $wgLang; $width = $opts->getValue( 'width' ); $height = $opts->getValue( 'height' ); // Define the object $plot = new PHPlot( $width, $height ); list( $legend, $resData ) = $this->getData( $opts ); $count = count( $resData ); $skip = intval( $count / ( $width / 60 ) - 1 ); $i = $count; foreach ( $resData as $date => $edits ) { if ( $skip > 0 ) { if ( ( $count - $i ) % $skip !== 0 ) $date = ''; } if ( strpos( $date, ';' ) !== false ) { list( , $date ) = explode( ';', $date, 2 ); } array_unshift( $edits, $date ); $data[] = $edits; $i--; } $font = FCFontFinder::find( $wgLang->getCode() ); if ( $font ) { $plot->SetDefaultTTFont( $font ); } else { $plot->SetDefaultTTFont( $wgTranslatePHPlotFont ); } $plot->SetDataValues( $data ); if ( $legend !== null ) { $plot->SetLegend( $legend ); } $numberFont = FCFontFinder::find( 'en' ); $plot->setFont( 'x_label', $numberFont, 8 ); $plot->setFont( 'y_label', $numberFont, 8 ); $yTitle = wfMsg( 'translate-stats-' . $opts['count'] ); // Turn off X axis ticks and labels because they get in the way: $plot->SetYTitle( $yTitle ); $plot->SetXTickLabelPos( 'none' ); $plot->SetXTickPos( 'none' ); $plot->SetXLabelAngle( 45 ); $max = max( array_map( 'max', $resData ) ); $max = self::roundToSignificant( $max, 1 ); $max = round( $max, intval( -log( $max, 10 ) ) ); $yTick = 10; while ( $max / $yTick > $height / 20 ) { $yTick *= 2; } // If we have very small case, ensure that there is at least one tick $yTick = min( $max, $yTick ); $yTick = self::roundToSignificant( $yTick ); $plot->SetYTickIncrement( $yTick ); $plot->SetPlotAreaWorld( null, 0, null, $max ); $plot->SetTransparentColor( 'white' ); $plot->SetBackgroundColor( 'white' ); // Draw it $plot->DrawGraph(); }
if ($stype == 'experience_avg_experimentclass') { $graph->SetPieLabelType('value'); } } $graph->SetTitle($stat['title']); if ($stat['xtitle']) { $graph->SetXTitle($stat['xtitle'], 'plotdown'); } // plotup, plotdown, both, none if ($stat['ytitle']) { $graph->SetYTitle($stat['ytitle'], 'plotleft'); } // plotleft, plotright, both, plotin, none // Remember that angles other than 90 are taken as 0 when working with fixed fonts. if (isset($stat['x_label_angle'])) { $graph->SetXLabelAngle($stat['x_label_angle']); } else { $graph->SetXLabelAngle(0); } $graph->SetYLabelAngle(0); if (!(isset($stat['tick_increment_y']) && $stat['tick_increment_y'])) { $stat['tick_increment_y'] = stats__get_y_increment($stat['data']); } $graph->SetYTickIncrement($stat['tick_increment_y']); $graph->SetXTickLabelPos('plotdown'); // plotup, plotdown, both, xaxis, none $graph->SetYTickLabelPos('both'); // plotleft, plotright, both, yaxis, none $graph->SetXTickPos('plotdown'); // plotup, plotdown, both, xaxis, none $graph->SetYTickPos('both');
/** * drawing the graph for a evaluation question * * @param array() $data * @param string $evalquestion_id */ function do_graph($data, $evalquestion_id) { global $tmp_path_export, $auth, $PATH_EXPORT; $type = do_graph_template(); //Define the object if ($type == "pie") { // Beim pie muss die Zeichenflaeche etwas groesser gewaehlt werden... $graph = new PHPlot(500, 300); } else { $graph = new PHPlot(300, 250); } if ($type == "pie") { // Beim pie muss das Array umgeformt werden. Bug in PHPlot? $tmp = array(); $tmp2 = array(); $legend = array(); array_push($tmp, "Test"); foreach ($data as $k => $d) { array_push($tmp, $d[1]); array_push($legend, $d[0]); } array_push($tmp2, $tmp); $data = $tmp2; $graph->SetLegend($legend); } //Data Colors $graph->SetDataColors(array("blue", "green", "yellow", "red", "PeachPuff", "orange", "pink", "lavender", "navy", "peru", "salmon", "maroon", "magenta", "orchid", "ivory"), array("black")); $max_x = max(array_map('next', $data)); $graph->SetPlotAreaWorld(NULL, 0); // y-achse bei 0 starten $graph->SetPrecisionY(0); //anzahl kommastellen y-achse $graph->SetYTickIncrement($max_x < 10 ? 1 : round($max_x / 10)); $graph->SetPlotBgColor(array(222, 222, 222)); $graph->SetDataType("text-data"); $graph->SetFileFormat(Config::get()->EVAL_AUSWERTUNG_GRAPH_FORMAT); $graph->SetOutputFile($tmp_path_export . "/evalsum" . $evalquestion_id . $auth->auth["uid"] . "." . Config::get()->EVAL_AUSWERTUNG_GRAPH_FORMAT); $graph->SetIsInline(true); $graph->SetDataValues($data); $graph->SetPlotType($type); $graph->SetXLabelAngle(count($data) < 10 ? 0 : 90); //$graph->SetShading(0); // kein 3D $graph->SetLineWidth(1); $graph->SetDrawXDataLabels(true); //Draw it $graph->DrawGraph(); }