# Testing phplot - Points require_once 'phplot.php'; # This array is used for both the point shapes and legend: $shapes = array('circle', 'cross', 'diamond', 'dot', 'halfline', 'line', 'plus', 'rect', 'triangle', 'trianglemid'); # 10 lines, one for each shape: $data = array(array('', 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), array('', 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), array('', 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), array('', 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), array('', 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), array('', 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), array('', 7, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), array('', 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17), array('', 9, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18), array('', 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19)); $p = new PHPlot(); $p->SetTitle('Points plots, 10 lines/10 shapes'); $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); # Need 10 different colors; defaults are not different: $p->SetDataColors(array('red', 'green', 'blue', 'yellow', 'cyan', 'magenta', 'brown', 'lavender', 'pink', 'orange')); # Show all 10 shapes: $p->SetPointShapes($shapes); # Also show that as the legend: $p->SetLegend($shapes); # 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('points'); $p->DrawGraph();
} # The variable $plot_type can be set in another script as well. if (empty($plot_type)) { $plot_type = 'linepoints'; } # Use data labels to display only the points we want, # but specify the same values for X to get the correct # spacing. $data = array(array('1990', 1990, 41308, 21015, 62634), array('1995', 1995, 44310, 13883, 61529), array('2000', 2000, 46772, 9000, 59421), array('2004', 2004, 46887, 7738, 57754), array('2006', 2006, 45441, 6888, 53179), array('2008', 2008, 42757, 5840, 49115)); $legend_text = array('Morning Papers', 'Evening Papers', 'Sunday Papers'); $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetTitle("US Daily Newspaper Circulation\n" . $plot_type . ' plot with SetLegendUseShapes(' . ($use_shapes ? 'True' : 'False') . ')'); $plot->SetPlotType($plot_type); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetPlotAreaWorld(1988, 0, 2010, 80000); $plot->SetYTickIncrement(10000); $plot->SetLegend($legend_text); $plot->SetXTickPos('none'); $plot->SetDrawXDataLabelLines(True); $plot->SetLegendUseShapes($use_shapes); // Use color boxes or shapes $plot->SetPointSizes(12); // Make points bigger for visibility $plot->SetLineStyles('solid'); // Make all lines solid $plot->SetLineWidths(2); // Make all lines thicker $plot->DrawGraph();
<?php # PHPlot Example: Point chart with error bars require_once 'phplot.php'; $data = array(array('', 1, 23.5, 5, 5), array('', 2, 20.1, 3, 3), array('', 3, 19.1, 2, 2), array('', 4, 16.8, 3, 3), array('', 5, 18.4, 4, 6), array('', 6, 20.5, 3, 2), array('', 7, 23.2, 4, 4), array('', 8, 23.1, 5, 2), array('', 9, 24.5, 2, 2), array('', 10, 28.1, 2, 2)); $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); $plot->SetPlotType('points'); $plot->SetDataType('data-data-error'); $plot->SetDataValues($data); # Main plot title: $plot->SetTitle('Points Plot With Error Bars'); # Set data range and tick increments to get nice even numbers: $plot->SetPlotAreaWorld(0, 0, 11, 40); $plot->SetXTickIncrement(1); $plot->SetYTickIncrement(5); # Draw both grids: $plot->SetDrawXGrid(True); $plot->SetDrawYGrid(True); # Is default # Set some options for error bars: $plot->SetErrorBarShape('tee'); # Is default $plot->SetErrorBarSize(10); $plot->SetErrorBarLineWidth(2); # Use a darker color for the plot: $plot->SetDataColors('brown'); $plot->SetErrorBarColors('brown'); # Make the points bigger so we can see them: $plot->SetPointSizes(10); $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(); }
$p->SetLegend($legend); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotType($plottype); $p->SetPlotAreaWorld(0, 0, 5, 10); $p->SetXDataLabelPos('none'); $p->SetXTickIncrement(1.0); $p->SetYTickIncrement(1.0); # Option: Use legend shape markers? $p->SetLegendUseShapes($useshapes); # Option: Use TT Font, set size and optional line spacing scale: if (!empty($fontsize)) { $p->SetFontTTF('legend', $font, $fontsize, $linespacing); } # Option: Varying point shape sizes: if ($setpointsizes) { $p->SetPointSizes(array(2, 4, 8, 10, 16)); } # Turn on backgrounds for visibility. $p->SetBackgroundColor('SkyBlue'); $p->SetDrawPlotAreaBackground(True); $p->SetPlotBgColor('plum'); # Option: Change alignment of lines/color boxes in legend? if (isset($textalign)) { $p->SetLegendStyle($textalign, $colorboxalign); } # Opton: Scale factor for color box width? if (isset($colorboxwidth)) { $p->legend_colorbox_width = $colorboxwidth; } $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(); }
# Case: 1 point_size, 1 point_shape $point_shapes = 'dot'; $point_sizes = 12; break; case 1: # Case: N>1 point_size, N point_shape $point_shapes = array('dot', 'box'); $point_sizes = array(6, 12); break; case 2: # Case: N point_size, >N point_shape $point_shapes = array('dot', 'box'); $point_sizes = 12; break; case 3: # Case: N point_size, <N point_shape $point_shapes = 'dot'; $point_sizes = array(6, 12); break; } $data = array(array('', 0, 1, 2, 3), array('', 1, 2, 3, 4), array('', 2, 3, 4, 5)); $p = new PHPlot(600, 400); $p->SetTitle("Point Sizes/Shapes (Bug 2963757) - case {$case}"); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetLineWidths(3); $p->SetLineStyles('solid'); $p->SetPointShapes($point_shapes); $p->SetPointSizes($point_sizes); $p->SetPlotType('linepoints'); $p->DrawGraph();
echo "Skipping test because it requires SetLegendTextColor()\n"; exit(2); // Tells test suite to skip this test } $title = 'Legend Text & Background Color Control (' . ($use_shapes ? 'marker shapes' : 'color boxes') . ')' . "\n" . "\nImage background color: " . ifset($image_bg_color) . "\nPlot area background color: " . ifset($plot_bg_color) . "\nLegend background color: " . ifset($legend_bg_color) . "\nLegend text color: " . ifset($legend_text_color) . "\nGeneral text color: " . ifset($text_color); $data = array(array('', 1, 1, 2, 3, 4, 5), array('', 2, 5, 1, 2, 3, 4), array('', 3, 4, 5, 1, 2, 3), array('', 4, 3, 4, 5, 1, 2), array('', 5, 2, 3, 4, 5, 1)); # Random legend lines, different lengths $legend = array('Data set 1', 'Data set 2', 'Error', 'Difference', 'Alternate'); $p = new PHPlot(800, 600); $p->SetTitle($title); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotType('points'); $p->SetLegend($legend); $p->SetPlotAreaWorld(0, 0, 6, 6); $p->SetPointSizes(8); # Wide left margin, leaving room for legend: $p->SetMarginsPixels(200); # Put the legend to the left of plot area, starting about 1/4 down: $p->SetLegendPosition(1, 0, 'plot', -0.1, 0.25); # Colors: if (!empty($image_bg_color)) { $p->SetBackgroundColor($image_bg_color); } if (!empty($plot_bg_color)) { $p->SetPlotBgColor($plot_bg_color); $p->SetDrawPlotAreaBackground(True); } if (!empty($legend_bg_color)) { $p->SetLegendBgColor($legend_bg_color); }