function make_plot($plot_type, $data_type, $nx, $ny) { $plot = new PHPlot(1280, 1024); $plot->SetPrintImage(False); $plot->SetFailureImage(False); $plot->SetDataType($data_type); $plot->SetDataValues(make_data_array($plot_type, $data_type, $nx, $ny, 100)); $plot->SetPlotType($plot_type); $plot->SetTitle("Serialize/Unserialize Tests\n{$plot_type} - {$data_type}"); $plot->SetXTickIncrement(5); $plot->SetYTickIncrement(10); $plot->SetPlotBorderType('full'); $plot->SetDrawXGrid(True); $plot->SetDrawYGrid(True); $plot->SetXTitle('X Axis Title'); $plot->SetYTitle('Y Axis Title'); # Select data labels or tick labels based on data type: if ($data_type == 'data-data') { $plot->SetXDataLabelPos('none'); $plot->SetXTickLabelPos('plotdown'); $plot->SetXTickPos('plotdown'); } elseif ($data_type == 'text-data') { $plot->SetXDataLabelPos('plotdown'); $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); } elseif ($data_type == 'data-data-yx') { $plot->SetYDataLabelPos('none'); $plot->SetYTickLabelPos('plotleft'); $plot->SetYTickPos('plotleft'); } elseif ($data_type == 'text-data-yx') { $plot->SetYDataLabelPos('plotleft'); $plot->SetYTickLabelPos('none'); $plot->SetYTickPos('none'); } return $plot; }
license@systemsmanager.net so we can mail you a copy immediately. */ include DIR_WS_CLASSES . 'phplot.php'; $year = $_GET['year'] ? $_GET['year'] : date('Y'); $month = $_GET['month'] ? $_GET['month'] : date('n'); $days = date('t', mktime(0, 0, 0, $month)) + 1; $stats = array(); for ($i = 1; $i < $days; $i++) { $stats[] = array($i, '0', '0'); } $banner_stats_query = smn_db_query("select dayofmonth(banners_history_date) as banner_day, banners_shown as value, banners_clicked as dvalue from " . TABLE_BANNERS_HISTORY . " where banners_id = '" . $banner_id . "' and month(banners_history_date) = '" . $month . "' and year(banners_history_date) = '" . $year . "'"); while ($banner_stats = smn_db_fetch_array($banner_stats_query)) { $stats[$banner_stats['banner_day'] - 1] = array($banner_stats['banner_day'], $banner_stats['value'] ? $banner_stats['value'] : '0', $banner_stats['dvalue'] ? $banner_stats['dvalue'] : '0'); } $graph = new PHPlot(600, 350, 'images/graphs/banner_daily-' . $banner_id . '.' . $banner_extension); $graph->SetFileFormat($banner_extension); $graph->SetIsInline(1); $graph->SetPrintImage(0); $graph->SetSkipBottomTick(1); $graph->SetDrawYGrid(1); $graph->SetPrecisionY(0); $graph->SetPlotType('lines'); $graph->SetPlotBorderType('left'); $graph->SetTitleFontSize('4'); $graph->SetTitle(sprintf(TEXT_BANNERS_DAILY_STATISTICS, $banner['banners_title'], strftime('%B', mktime(0, 0, 0, $month)), $year)); $graph->SetBackgroundColor('white'); $graph->SetVertTickPosition('plotleft'); $graph->SetDataValues($stats); $graph->SetDataColors(array('blue', 'red'), array('blue', 'red')); $graph->DrawGraph(); $graph->PrintImage();
<?php # $Id$ # Testing phplot - data-data ordering require_once 'phplot.php'; # 10 lines, one for each shape: $data = array(array('', 1, 20), array('', 2, 2), array('', 3, 19), array('', 4, 3), array('', 6, 4), array('', 7, 17), array('', 8, 5), array('', 9, 16), array('', 5, 18), array('', 10, 6)); $p = new PHPlot(); $p->SetTitle('Out-of-order data-data points'); $p->SetPlotType('lines'); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotAreaWorld(0, 0, 12, 25); $p->SetXTickIncrement(1); $p->SetYTickIncrement(1); # We don't use the data labels (all set to '') so might as well turn them off: $p->SetXDataLabelPos('none'); # Draw both grids: $p->SetDrawXGrid(True); $p->SetDrawYGrid(True); # The default $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();
<?php # PHPlot Example: Linepoints plot with Data Value Labels require_once 'phplot.php'; $data = array(array('1995', 135), array('1996', ''), array('1997', ''), array('1998', ''), array('1999', ''), array('2000', 225), array('2001', ''), array('2002', ''), array('2003', 456), array('2004', 420), array('2005', 373), array('2006', 300), array('2007', 255), array('2008', 283)); $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetPlotType('linepoints'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); $plot->SetTitle("US Federal Emergency Food Assistance, 1995 - 2008\n" . "(in \$ millions)"); # Turn on Y data labels: $plot->SetYDataLabelPos('plotin'); # Turn on X data label lines (drawn from X axis up to data point): $plot->SetDrawXDataLabelLines(True); # With Y data labels, we don't need Y ticks, Y tick labels, or grid lines. $plot->SetYTickLabelPos('none'); $plot->SetYTickPos('none'); $plot->SetDrawYGrid(False); # X tick marks are meaningless with this data: $plot->SetXTickPos('none'); $plot->SetXTickLabelPos('none'); $plot->DrawGraph();
# Printing helper function prif($name, &$var, $before = '') { return "{$before} {$name}=" . (isset($var) ? $var : "n/a"); } # Auto title: $title = 'X/Y Tick Anchors' . (empty($subtitle) ? "\n" : " - {$subtitle}\n") . prif('X tick anchor', $x_tick_anchor) . prif('Y tick anchor', $y_tick_anchor, ',') . prif('X tick inc.', $x_tick_step, ',') . prif('Y tick inc.', $y_tick_step, ','); $data = array(); for ($x = $start; $x <= $stop; $x += $delta) { $data[] = array('', $x, $x); } $plot = new PHPlot(800, 600); $plot->SetTitle($title); $plot->SetPlotType('lines'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetDrawXGrid(True); $plot->SetDrawYGrid(True); if (isset($x_tick_step)) { $plot->SetXTickIncrement($x_tick_step); } if (isset($y_tick_step)) { $plot->SetYTickIncrement($y_tick_step); } if (isset($x_tick_anchor)) { $plot->SetXTickAnchor($x_tick_anchor); } if (isset($y_tick_anchor)) { $plot->SetYTickAnchor($y_tick_anchor); } $plot->DrawGraph();
<?php include DIR_WS_CLASSES . 'phplot.php'; $stats = array(); $banner_stats_query = tep_db_query("select dayofmonth(banners_history_date) as name, banners_shown as value, banners_clicked as dvalue from " . TABLE_BANNERS_HISTORY . " where banners_id = '" . $banner_id . "' and to_days(now()) - to_days(banners_history_date) < " . $days . " order by banners_history_date"); while ($banner_stats = tep_db_fetch_array($banner_stats_query)) { $stats[] = array($banner_stats['name'], $banner_stats['value'], $banner_stats['dvalue']); } if (sizeof($stats) < 1) { $stats = array(array(date('j'), 0, 0)); } $graph = new PHPlot(200, 220, 'images/graphs/banner_infobox-' . $banner_id . '.' . $banner_extension); $graph->SetFileFormat($banner_extension); $graph->SetIsInline(1); $graph->SetPrintImage(0); $graph->draw_vert_ticks = 0; $graph->SetSkipBottomTick(1); $graph->SetDrawXDataLabels(0); $graph->SetDrawYGrid(0); $graph->SetPlotType('bars'); $graph->SetDrawDataLabels(1); $graph->SetLabelScalePosition(1); $graph->SetMarginsPixels(15, 15, 15, 30); $graph->SetTitleFontSize('4'); $graph->SetTitle('TEXT_BANNERS_LAST_3_DAYS'); $graph->SetDataValues($stats); $graph->SetDataColors(array('blue', 'red'), array('blue', 'red')); $graph->DrawGraph(); $graph->PrintImage();
$graph->SetYTickIncrement($which_yti); $graph->SetXTickIncrement($which_xti); $graph->SetXTickLength($which_xtl); $graph->SetYTickLength($which_ytl); $graph->SetXTickCrossing($which_xtc); $graph->SetYTickCrossing($which_ytc); $graph->SetXTickPos($which_xtick_pos); $graph->SetYTickPos($which_ytick_pos); $graph->SetShading($which_shading); $graph->SetLineWidth($which_line_width); $graph->SetErrorBarLineWidth($which_errorbar_line_width); $graph->SetDrawDashedGrid($which_dashed_grid); switch ($which_draw_grid) { case 'x': $graph->SetDrawXGrid(TRUE); $graph->SetDrawYGrid(FALSE); break; case 'y': $graph->SetDrawXGrid(FALSE); $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);
if ($_POST['GraphValue'] == 'Net') { $graph->SetYTitle(_('Sales Value')); } elseif ($_POST['GraphValue'] == 'GP') { $graph->SetYTitle(_('Gross Profit')); } else { $graph->SetYTitle(_('Quantity')); } $graph->SetXTickPos('none'); $graph->SetXTickLabelPos('none'); $graph->SetBackgroundColor('white'); $graph->SetTitleColor('blue'); $graph->SetFileFormat('png'); $graph->SetPlotType($_POST['GraphType']); $graph->SetIsInline('1'); $graph->SetShading(5); $graph->SetDrawYGrid(TRUE); $graph->SetDataType('text-data'); $SalesResult = DB_query($SQL, $db); if (DB_error_no($db) != 0) { prnMsg(_('The sales graph data for the selected criteria could not be retrieved because') . ' - ' . DB_error_msg($db), 'error'); include 'includes/footer.inc'; exit; } if (DB_num_rows($SalesResult) == 0) { prnMsg(_('There is not sales data for the criteria entered to graph'), 'info'); include 'includes/footer.inc'; exit; } $GraphArrays = array(); $i = 0; while ($myrow = DB_fetch_array($SalesResult)) {
$label[30] = "Day 30"; Error_Reporting(0); for ($i = 0; $i <= 30; $i++) { $a += rand(-1, 2); $b = $a * rand(0, 1) / 10; $c = $a * rand(0, 1) / 10; $data[] = array("{$label[$i]}", $i + 1, $a, $b, $c); } //Define the data for error bars $graph->SetDataType("linear-linear-error"); //Must be first thing //Set the Graph particulars $graph->SetPrecisionX(0); $graph->SetPrecisionY(0); $graph->SetUseTTF("0"); $graph->SetDrawYGrid("1"); // 1 = true $graph->SetDataValues($data); $graph->SetImageArea(600, 400); $graph->SetVertTickIncrement(""); $graph->SetHorizTickIncrement(1); $graph->SetErrorBarLineWidth(1); $graph->SetYScaleType("log"); $graph->SetPointShape("halfline"); $graph->SetErrorBarShape("line"); $graph->SetPlotType("points"); $graph->SetXGridLabelType("title"); $graph->SetXLabel("Day"); $graph->SetYLabel("index"); $graph->SetTitle("Stock Market Data"); //$graph->SetErrorBarColors(array("blue","red","green","black"));
function guifi_stats_chart03() { 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\n from {guifi_location} 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 MONTH(FROM_UNIXTIME(timestamp_created)) "; $result = db_query($vsql); $tot = 0; $valor = 0; while ($record = db_fetch_object($result)) { $tot += $record->num; $data[] = array("{$record->mes}", $record->num); } foreach ($data as &$dat) { $dat[1] = $dat[1] * 100 / $tot; } $shapes = array('none'); $plot = new PHPlot($gwidth, $gheight); $plot->SetPlotAreaWorld(0, 0, NULL, NULL); $plot->SetFileFormat('png'); $plot->SetDataType("text-data"); $plot->SetDataValues($data); $plot->SetPlotType("bars"); //$plot->SetYTickIncrement(10); $plot->SetSkipBottomTick(TRUE); $plot->SetSkipLeftTick(TRUE); $plot->SetTickLength(0); $plot->SetXTickPos('none'); $plot->SetYTickPos('none'); $plot->SetDrawYGrid(FALSE); $plot->SetYTickLabelPos('none'); $plot->SetYDataLabelPos('plotin'); $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('Monthly average')); } else { $plot->SetTitle("guifi.net " . t('zone') . ": " . guifi_get_zone_name($zone_id) . "\n" . t('Monthly average')); } } $plot->SetXTitle(t('Months')); $plot->SetYTitle(t('% Working nodes')); $plot->SetXDataLabelPos('plotdown'); $plot->SetXLabelAngle(0); $plot->SetYLabelType('data', 2); $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->SetIsInline(TRUE); $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(); }