# Reload data colors and apply alpha to all: if (isset($tp['alpha'])) { $p->SetDataColors(NULL, NULL, $tp['alpha']); $title[] = "Alpha=" . $tp['alpha']; } $p->SetFileFormat($tp['output']); $title[] = strtoupper($tp['output']) . ' Output'; if ($tp['antialias']) { $title[] = "Antialiased"; } if ($tp['noalphablend']) { $title[] = "No alpha blending"; } if (isset($tp['gamma'])) { $title[] = "Gamma=" . $tp['gamma']; } if ($tp['savealpha']) { $title[] = "Save alpha"; } $p->SetTitle(implode(', ', $title)); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetLineWidths(3); $p->SetLineStyles('solid'); $p->SetPlotType('lines'); $p->SetXTickIncrement(1); $p->SetYTickIncrement(1); $p->SetDrawDashedGrid(False); // Or it doesn't show with anti-aliasing $p->SetDrawXGrid(True); $p->DrawGraph();
<?php # Testing phplot - Line-Points, extensions to suppress either # the line or the points on each plot. # $Id$ require_once 'phplot.php'; $data = array(array('', 1, 1, 2, 3), array('', 2, 2, 3, 4), array('', 3, 3, 4, 5), array('', 4, 4, 5, 6), array('', 5, 5, 6, 7), array('', 6, 6, 7, 8), array('', 7, 7, 8, 9), array('', 8, 8, 9, 10), array('', 9, 9, 10, 11), array('', 10, 10, 11, 12)); $p = new PHPlot(); $p->SetTitle('PlotType: linepoints with suppression'); $p->SetDataType('data-data'); $p->SetDataValues($data); # We don't use the data labels (all set to '') so might as well turn them off: $p->SetXDataLabelPos('none'); # Need to set area and ticks to get reasonable choices. # Increase X range to make room for the legend. $p->SetPlotAreaWorld(0, 0, 13, 20); $p->SetXTickIncrement(1); $p->SetYTickIncrement(2); $p->SetDataColors(array('red', 'green', 'blue')); $p->SetPointShapes(array('circle', 'none', 'diamond')); $p->SetLineStyles(array('solid', 'solid', 'none')); $p->SetLegend(array('circle+line', 'line only', 'diamond only')); # Make the points bigger so we can see them: $p->SetPointSizes(10); # Draw both grids: $p->SetDrawXGrid(True); $p->SetDrawYGrid(True); # The default $p->SetPlotType('linepoints'); $p->DrawGraph();
require_once 'phplot.php'; $np = $tp['nlines']; $data = array(); for ($i = 1; $i <= 20; $i++) { $row = array('', $i); for ($j = 1; $j <= $np; $j++) { $row[] = $i + $j; } $data[] = $row; } $p = new PHPlot(800, 600); $p->SetTitle($tp['title'] . $tp['suffix']); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotAreaWorld(0, 0, 21, 40); $p->SetXTickIncrement(1); $p->SetYTickIncrement(5); # Options: if (isset($tp['LWidths'])) { $p->SetLineWidths($tp['LWidths']); } if (isset($tp['DStyle'])) { $p->SetDefaultDashedStyle($tp['DStyle']); } if (isset($tp['LStyles'])) { $p->SetLineStyles($tp['LStyles']); } $p->SetDrawXGrid(False); $p->SetDrawYGrid(False); $p->SetPlotType('lines'); $p->DrawGraph();
// Will suppress the label $max_indexes[] = $max_index; } return $max_indexes; } # Custom label formatting function: Return an empty string, unless this is # the largest value in the row. function fmt_label($value, $maxes, $row, $column) { if ($maxes[$row] == $column) { return $value; } return ""; } # Get the data array with 11 rows, 6 values per row: $data = make_data_array(11, 6); # Process the data array to find the largest Y per row: $max_indexes = find_max_indexes($data); # Now plot the data: $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); // For presentation in the manual $plot->SetPlotType('linepoints'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetTitle('Linepoints plot with only max Y values labeled'); $plot->SetYDataLabelPos('plotin'); $plot->SetYDataLabelType('custom', 'fmt_label', $max_indexes); $plot->SetLineStyles('solid'); $plot->SetYTickIncrement(100); $plot->DrawGraph();
# Testing phplot - "Typical" plot with lots of elements, for manual require_once 'phplot.php'; $data = array(array('', -4, -64, 16, 40), array('', -3, -27, 9, 30), array('', -2, -8, 4, 20), array('', -1, -1, 1, 10), array('', 0, 0, 0, 0), array('', 1, 1, 1, -10), array('', 2, 8, 4, -20), array('', 3, 27, 9, -30), array('', 4, 64, 16, -40)); # Size of plot is set by PDF 72dpi resolution: $p = new PHPlot(400, 300); $p->SetDataType('data-data'); $p->SetDataValues($data); # Titles: $p->SetTitle('A Plot Containing Some Lines'); $p->SetXTitle('Independent Variable'); $p->SetYTitle('Dependent Variable'); # We don't use the data labels (all set to '') so might as well turn them off: $p->SetXDataLabelPos('none'); # Need to set area and ticks to get reasonable choices. $p->SetPlotAreaWorld(-4, -70, 4, 80); $p->SetXTickIncrement(1); $p->SetYTickIncrement(10); # Don't use dashes for 3rd line: $p->SetLineStyles(array('solid', 'dashed', 'solid')); # Make the lines thicker: $p->SetLineWidths(2); # Image border: $p->SetImageBorderType('raised'); $p->SetImageBorderColor('blue'); # Draw both grids: $p->SetDrawXGrid(True); $p->SetDrawYGrid(True); # And a legend: $p->SetLegend(array('x^3', 'x^2', '-10x')); $p->SetPlotType('lines'); $p->DrawGraph();
<?php # PHPlot Example - Box Plot with outliers and line styles require_once 'phplot.php'; # Data array: each row is (label, X, Ymin, YQ1, Ymid, YQ3, Ymax, [Youtlier...]) $data = array(array('', 1, 10, 15, 20, 25, 30), array('', 2, 12, 14, 18, 20, 24, 6, 8, 28), array('', 3, 5, 11, 19, 28, 35), array('', 4, 14, 17, 21, 26, 28, 9, 12, 35, 32), array('', 5, 12, 15, 22, 27, 30), array('', 6, 15, 18, 20, 22, 26, 12), array('', 7, 10, 15, 21, 26, 28, 32), array('', 8, 11, 15, 20, 24, 27, 6, 8), array('', 9, 10, 15, 19, 22, 26, 4, 34)); $plot = new PHPlot(800, 600); $plot->SetTitle('Box Plot with outliers and styles'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetPlotType('boxes'); $plot->SetImageBorderType('plain'); // Improves presentation in the manual # Use dashed lines for the upper and lower whiskers: $plot->SetLineStyles('dashed'); # Make the box and belt use a thicker line: $plot->SetLineWidths(array(3, 3, 1)); # Make the outliers red, and everything else blue: $plot->SetDataColors(array('blue', 'blue', 'red', 'blue')); # Draw the outliers using a "star": $plot->SetPointShapes('star'); $plot->DrawGraph();
function graficarDemandaPronosticoError($oData) { $sql = "select\r\n\t\t\t\tdate_format(c1.fecha_fin, '%d/%m/%Y') fecha_fin, \r\n\t\t\t\tcantidad_demandada, \r\n\t\t\t\tprediccion, \r\n\t\t\t\terror,\r\n\t\t\t\tsenial \r\n\t\t\t\tfrom (\r\n\t\t\t\t\tselect\r\n\t\t\t\t\tfecha_fin, \r\n\t\t\t\t\tcantidad_demandada, \r\n\t\t\t\t\tprediccion, \r\n\t\t\t\t\terror, \r\n\t\t\t\t\tsenial \r\n\t\t\t\t\tfrom predicciones t1 \r\n\t\t\t\t\tinner join periodos t2 on t1.id_periodo = t2.id_periodo \r\n\t\t\t\t\twhere id_producto= " . $oData["id_producto"] . " \r\n\t\t\t\t\torder by fecha_fin asc) c1"; $rs = getRS($sql); $data = array(); $nro = getNrosRows($rs); $flag = 1; if ($nro) { while ($row = getRow($rs)) { if ($flag) { $inicio = $row['fecha_fin']; $flag = 0; } $nro--; if ($nro == 0) { $fin = $row['fecha_fin']; } $data[] = array('', $row['cantidad_demandada'], $row['prediccion'], $row['error'], $row['senial']); } } $plot = new PHPlot(800, 465); //$plot->SetImageBorderType('plain'); $plot->SetPlotType('lines'); //tipo de gráfico $plot->SetDataType('text-data'); $plot->SetDataValues($data); $plot->SetTitle('Demanda real, predicción, error y señal de rastreo. Periodo ' . $inicio . ' al ' . $fin); //Título $plot->SetLegend(array('Demanda real', 'Pronóstico', 'Error', 'Señal de rastreo')); //Referencia $plot->SetLineWidths(2); //ancho de la linea $plot->SetLineStyles("solid"); //estilo de la linea $plot->SetDataColors(array('green', 'blue', 'red', 'purple')); $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); # Draw both grids: $plot->SetDrawXGrid(True); $plot->SetDrawYGrid(True); $plot->DrawGraph(); }
$widths[$j] = $width++; } } } else { for ($j = 0; $j < $ny; $j++) { $widths[$j] = $j + 1; } } } if ($set_styles) { // $p->SetDefaultDashedStyle('10-5'); $p->SetDrawYGrid(False); // Hard to see dashed lines with dashed grid. } // Always do SetLineStyles (if set_styles is false, it sets them all to solid) $p->SetLineStyles($styles); if ($set_linewidths) { $p->SetLineWidths($widths); } $p->SetLegend($legend); $p->SetLegendPosition(0, 0, 'plot', 0, 0, 5, 5); if ($legend_use_shapes) { $p->SetLegendUseShapes(True); } $p->SetPlotBgColor('black'); if ($plot_area_background) { $p->SetDrawPlotAreaBackground(True); } if (isset($colorbox_width)) { $p->legend_colorbox_width = $colorbox_width; }
$graph->SetLineWidth("1"); $graph->SetDrawYGrid("1"); // 1 = true $graph->SetPointShape("{$which_dot}"); $graph->SetErrorBarShape("{$which_error_type}"); $graph->SetXLabel($xlbl); $graph->SetYLabel($ylbl); $graph->SetTitle($title); $graph->SetXAxisPosition($which_xap); $graph->SetDataColors(array("blue", "green", "yellow", "red"), array("black")); if ($maxy_in) { if ($which_data_type = "text-linear") { $graph->SetPlotAreaWorld(0, $miny_in, count($data), $maxy_in); } } $graph->SetLineStyles(array("dashed", "dashed", "solid", "solid")); $graph->SetLegend(array("A", "Bee", "Cee", "Dee")); //$graph->SetPlotAreaWorld(0,100,5.5,1000); //$graph->SetPlotAreaWorld(0,-10,6,35); //$graph->SetPlotAreaPixels(150,50,600,400); /* //Even more settings $graph->SetPlotBgColor(array(222,222,222)); $graph->SetBackgroundColor(array(200,222,222)); //can use rgb values or "name" values $graph->SetTextColor("black"); $graph->SetGridColor("black"); $graph->SetLightGridColor(array(175,175,175)); $graph->SetTickColor("black"); $graph->SetTitleColor(array(0,0,0)); // Can be array or name */ $graph->DrawGraph();
/** * Generate a graph for this tag * @param string $tag * @param string $filePath * @return bool, success */ public function makePngGraph( $tag, $filePath ) { if( !function_exists( 'ImageCreate' ) ) { // GD is not installed return false; } global $wgPHPlotDir, $wgMemc; require_once( "$wgPHPlotDir/phplot.php" ); // load classes // Define the object $plot = new PHPlot( 1000, 400 ); // Set file path $dir = dirname($filePath); // Make sure directory exists if( !file_exists($dir) && !wfMkdirParents( $dir, 0777, __METHOD__ ) ) { throw new MWException( 'Could not create file directory!' ); } $plot->SetOutputFile( $filePath ); $plot->SetIsInline( true ); $data = array(); $totalVal = $totalCount = $n = 0; // Define the data using the DB rows list($res,$u,$maxC,$days) = $this->doQuery( $tag ); if( !$maxC ) { return false; } // Label spacing $int = intval( ceil($days/10) ); // 10 labels at most foreach( $res as $row ) { $totalVal += (int)$row->rfh_total; $totalCount += (int)$row->rfh_count; $dayCount = (real)$row->rfh_count; if( !$row->rfh_count ) { continue; // bad data } // Nudge values up by 1 $dayAve = 1 + (real)$row->rfh_total/(real)$row->rfh_count; $cumAve = 1 + (real)$totalVal/(real)$totalCount; $year = intval( substr( $row->rfh_date, 0, 4 ) ); $month = intval( substr( $row->rfh_date, 4, 2 ) ); $day = intval( substr( $row->rfh_date, 6, 2 ) ); # Fill in days with no votes to keep spacing even if( isset($lastDate) ) { $dayGap = wfTimestamp(TS_UNIX,$row->rfh_date) - wfTimestamp(TS_UNIX,$lastDate); $x = intval( $dayGap/86400 ); # Day gaps... for( $x; $x > 1; --$x ) { $data[] = array("",$lastDAve,$lastRAve,0); $n++; } } $n++; # Label point? if( $n >= $int || !count($data) ) { $p = ($days > 31) ? "{$month}-".substr( $year, 2, 2 ) : "{$month}/{$day}"; $n = 0; } else { $p = ""; } $data[] = array( $p, $dayAve, $cumAve, $dayCount ); $lastDate = $row->rfh_date; $lastDAve = $dayAve; $lastRAve = $cumAve; } // Minimum sample size if( count($data) < 2 ) { return false; } // Re-scale voter count to fit to graph $this->dScale = ceil($maxC/5); // Cache the scale value to memory $key = wfMemcKey( 'feedback', 'scale', $this->page->getArticleId(), $this->period ); $wgMemc->set( $key, $this->dScale, 7*24*3600 ); // Fit to [0,4] foreach( $data as $x => $dataRow ) { $data[$x][3] = $dataRow[3]/$this->dScale; } $plot->SetDataValues($data); $plot->SetPointShapes( array('dot','dot','dot') ); $plot->setPointSizes( array(1,1,4) ); $plot->SetDataColors( array('blue','green','red') ); $plot->SetLineStyles( array('solid','solid','solid') ); $plot->SetBackgroundColor('#F8F8F8'); // Turn off X axis ticks and labels because they get in the way: $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); $plot->SetYTickIncrement( .5 ); // Set plot area $plot->SetPlotAreaWorld( 0, 0, null, 5 ); // Show total number of votes $plot->SetLegend( array("#{$totalCount}") ); // Draw it! $plot->DrawGraph(); return true; }