<?php # $Id$ # Test: area plot with raised X axis require_once 'phplot.php'; $data = array(array('A', 4, 3, 2, 1), array('B', 5, 4, 3, 2), array('C', 6, 5, 4, 3), array('D', 7, 6, 5, 4)); $plot = new PHPlot(800, 600); $plot->SetTitle('Area plot with X axis raised to 3'); $plot->SetPlotType('area'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); $plot->SetXAxisPosition(3); $plot->SetYTickIncrement(1); $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); $plot->DrawGraph();
$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); } } /* //Even more settings $graph->SetPlotAreaWorld(0,100,5.5,1000); $graph->SetPlotAreaWorld(0,-10,6,35); $graph->SetPlotAreaPixels(150,50,600,400); $graph->SetDataColors(
$graph->SetLineWidth(1); $graph->SetPlotAreaWorld(883634400, 1, 915095000, 140); $graph->DrawGraph(); //Now do the second chart on the image unset($example_data); $graph->SetPrintImage(1); //Now draw the image $graph->SetYScaleType("linear"); include "./data_date.php"; $graph->SetDataType("data-data"); //Must be called before SetDataValues $graph->SetDataValues($example_data); $graph->SetNewPlotAreaPixels(90, 260, 540, 350); $graph->SetDataValues($example_data); $graph->SetXGridLabelType("time"); $graph->SetXDataLabelAngle(90); $graph->SetXLabel(""); $graph->SetYLabel("Volume"); $graph->SetVertTickIncrement(30); $graph->SetPlotType("thinbarline"); //Set how to display the x-axis ticks $graph->SetXTimeFormat("%b %y"); $graph->SetHorizTickIncrement(2679000); $graph->SetXAxisPosition(0); //Have to reset it after log plots //Set Plot to go from x = Jan 1 1998, to x = Dec 31 1998 // and from y = 0 to y = 90 $graph->SetPlotAreaWorld(883634400, 0, 915095000, 90); $graph->DrawGraph(); //Print the image $graph->PrintImage();
<?php # $Id$ # Testing phplot - axes controls require_once 'phplot.php'; # This is Y = X^3/8 for X = [-4:4] $data = array(array('', -4, -8), array('', -3, -3.375), array('', -2, -1), array('', -1, -0.125), array('', 0, 0), array('', 1, 0.125), array('', 2, 1), array('', 3, 3.375), array('', 4, 8)); $p = new PHPlot(400, 300); $p->SetDataType('data-data'); $p->SetDataValues($data); # Titles: $p->SetTitle("Axes Tests\nForce X axis to Y=-3"); # Axis positions: $p->SetXAxisPosition(-3); $p->SetYAxisPosition(0); # 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(-5, -10, 5, 10); $p->SetXTickIncrement(1); $p->SetYTickIncrement(1); # Draw both grids: $p->SetDrawXGrid(True); $p->SetDrawYGrid(True); $p->SetPlotType('lines'); $p->DrawGraph();
} $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); $plot->SetPlotType('stackedbars'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); if ($tp['compat']) { # backward compatible mode $plot->SetTitle('Candy Sales by Month and Product'); $plot->SetYTitle('Millions of Units'); $plot->SetLegend(array('Chocolates', 'Mints', 'Hard Candy', 'Sugar-Free')); } else { $plot->SetTitle($tp['title'] . $tp['suffix']); $plot->SetXTitle('Month'); $plot->SetYTitle('Number of Units'); } $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); if (isset($tp['shading'])) { $plot->SetShading($tp['shading']); } if (isset($tp['xaxispos'])) { $plot->SetXAxisPosition($tp['xaxispos']); } if (isset($tp['ydatalabel'])) { $plot->SetYDataLabelPos($tp['ydatalabel']); } if (isset($tp['custom'])) { call_user_func($tp['custom'], $plot); } $plot->DrawGraph();
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(); }
# This is a cubic equation with roots at -8, 2, 10 for ($x = -10; $x <= 10; $x++) { $data[] = array('', $x, ($x + 8) * ($x - 2) * ($x - 10)); } $p = new PHPlot(400, 800); $p->SetPrintImage(FALSE); $p->SetPlotBorderType('full'); $p->SetTitle("Set/Reset Parameters Test (2)\n" . "Top: Parameters Set\n" . "Bottom: Parameters Reset"); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotType('lines'); $p->SetLegend('Y = F(X)'); $p->SetLegendPixels(100, 200); $p->SetNumXTicks(5); $p->SetNumYTicks(8); $p->SetXTitle('X Axis with 5 ticks'); $p->SetYTitle('Y Axis with 8 ticks'); $p->SetXAxisPosition(-228); $p->SetYAxisPosition(7); $p->SetPlotAreaPixels(70, 80, 380, 400); $p->DrawGraph(); $p->SetLegendPixels(); $p->SetNumXTicks(); $p->SetNumYTicks(); $p->SetXTitle('X Axis'); $p->SetYTitle('Y Axis'); $p->SetXAxisPosition(); $p->SetYAxisPosition(); $p->SetPlotAreaPixels(70, 450, 380, 750); $p->DrawGraph(); $p->PrintImage();
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(); }
$a = 0.5; $d_theta = M_PI / 48.0; for ($theta = M_PI * 7; $theta >= 0; $theta -= $d_theta) { $data[] = array('', $a * $theta * cos($theta), $a * $theta * sin($theta)); } $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); $plot->SetPlotType('points'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); # Main plot title: $plot->SetTitle('Scatterplot (points plot)'); # Need to set area and ticks to get reasonable choices. $plot->SetPlotAreaWorld(-12, -12, 12, 12); $plot->SetXTickIncrement(2); $plot->SetYTickIncrement(2); # Move axes and ticks to 0,0, but turn off tick labels: $plot->SetXAxisPosition(0); # Is default $plot->SetYAxisPosition(0); $plot->SetXTickPos('xaxis'); $plot->SetXTickLabelPos('none'); $plot->SetYTickPos('yaxis'); $plot->SetYTickLabelPos('none'); # Turn on 4 sided borders, now that axes are inside: $plot->SetPlotBorderType('full'); # Draw both grids: $plot->SetDrawXGrid(True); $plot->SetDrawYGrid(True); # Is default $plot->DrawGraph();
$px_l = 40; // Left offset $px_r = 5; // Right inset # Sub-plot (1) shows the initial plot range = date range. $plot->SetPlotAreaPixels($px_l, $py1, $pdx - $px_r, $py2); $plot->SetXTitle('(1) Initial Range'); # Disable zero magnet and range adjustment: $plot->TuneYAutoRange(0, 'R', 0); $plot->DrawGraph(); # Sub-plot (2) shows the plot range after zero magnet. $plot->SetPlotAreaPixels($pdx + $px_l, $py1, 2 * $pdx - $px_r, $py2); $plot->SetXTitle('(2) Zero Magnet'); # Reset to auto-range, auto-axis: $plot->SetPlotAreaWorld(NULL, NULL, NULL, NULL); $plot->SetXAxisPosition(NULL); # Set zero magnet on, leave range adjust off: $plot->TuneYAutoRange(1, 'R', 0); $plot->DrawGraph(); # Sub-plot (3) shows the plot range after end adjust / increase range. $plot->SetPlotAreaPixels(2 * $pdx + $px_l, $py1, 3 * $pdx - $px_r, $py2); $plot->SetXTitle('(3) End Adjustment'); # Reset to auto-range, auto-axis: $plot->SetPlotAreaWorld(NULL, NULL, NULL, NULL); $plot->SetXAxisPosition(NULL); # Set zero magnet on, end adjust on, but leave at mode R - don't go to tick. $plot->TuneYAutoRange(1, 'R', 0.03); $plot->DrawGraph(); # Sub-plot (4) shows the plot range after end adjust / adjust to tick. $plot->SetPlotAreaPixels(3 * $pdx + $px_l, $py1, 4 * $pdx - $px_r, $py2); $plot->SetXTitle('(4) Adjust to Tick');
<?php # $Id$ # Stacked bar plots with data labels, raised X axis covering some points require_once 'phplot.php'; $data = array(array('A', 2, 2, 2), array('B', 3, 3, 3), array('C', 4, 4, 4), array('D', 5, 5, 5), array('E', 6, 6, 6), array('F', 7, 7, 7), array('G', 8, 8, 8)); $plot = new PHPlot(800, 600); $plot->SetPlotType('stackedbars'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); $plot->SetTitle('Stacked Bars - Raised axis covers segments'); $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); $plot->SetXAxisPosition(7); $plot->SetYTickIncrement(1); $plot->SetYDataLabelPos('plotstack'); $plot->DrawGraph();
<?php include "./data_date2.php"; include "../phplot.php"; $graph = new PHPlot(); $graph->SetDataType("data-data-error"); //Must be called before SetDataValues $graph->SetImageArea(600, 400); $graph->SetPrecisionY(0); $graph->SetXLabel(""); $graph->SetYLabel("Volume"); $graph->SetVertTickIncrement(20); $graph->SetXAxisPosition(1); //$graph->SetSkipBottomTick(1); //Set Unixtime Increment and X Axis Settings $graph->SetHorizTickIncrement(2679000); $graph->SetXGridLabelType("time"); $graph->SetXTimeFormat("%b %y"); $graph->SetXDataLabelAngle(90); $graph->SetDataValues($example_data); $graph->SetPlotType("lines"); $graph->SetErrorBarShape("line"); $graph->SetPointShape("halfline"); $graph->SetYScaleType("log"); $graph->SetLineWidth(1); $graph->SetDrawXDataLabels(false); //Since X axis is in Unixtime format we set the limits accordingly $graph->SetPlotAreaWorld(883634400, 1, 915095000, 140); $graph->DrawGraph();