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();
//$p->SetDefaultTTFont('./arial.ttf'); # Set the main plot title: $p->SetTitle('Histórico 10 dias'); $p->SetPrecisionY(1); # Select the data array representation and store the data: $p->SetDataType('text-data'); $p->SetDataValues($data); # Select the plot type - bar chart: $p->SetPlotType('lines'); # Define the data range. PHPlot can do this automatically, but not as well. //$p->SetPlotAreaWorld(0, 0, 9, 400); # Select an overall image background color and another color under the plot: //$p->SetBackgroundColor('#ffffcc'); //$p->SetDrawPlotAreaBackground(True); //$p->SetPlotBgColor('#ffffff'); # Draw lines on all 4 sides of the plot: $p->SetPlotBorderType('full'); # Set a 3 line legend, and position it in the upper left corner: //$p->SetLegend(array('Acessos')); //$p->SetLegendWorld(0.1, 95); # Turn data labels on, and all ticks and tick labels off: //$p->SetXDataLabelPos('plotdown'); $p->SetXLabelFontSize(2); $p->SetAxisFontSize(2); $p->SetXTickPos('none'); //$p->SetXTickLabelPos('none'); //$p->SetYTickPos('none'); //$p->SetYTickLabelPos('none'); $p->SetYDataLabelPos('plotin'); # Generate and output the graph now: $p->DrawGraph();
$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( array("blue","green","yellow","red"), //Data Colors array("black") //Border Colors
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(); }
function guifi_stats_chart07() { 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; } $today = getdate(); $year = $today[year]; $month = $today[mon]; $month = $month - 12; $n = 0; $tot = 0; if ($month < 1) { $year = $year - 1; $month = 12 + $month; } $datemin = mktime(0, 0, 0, $month, 1, $year); if (isset($_GET['zone'])) { $zone_id = $_GET['zone']; if ($zone_id == "0") { $zone_id = "0"; } //"3671"; } else { $zone_id = "0"; } $avalue = array(); $adata = array(); for ($i = 0; $i < 10; $i++) { $adata[] = array(0, 0); } $vsql = "select sum(if(timestamp_created >= " . $datemin . ",1,0)) as num, count(*) as total, zone_id\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 zone_id "; $result = db_query($vsql); while ($record = db_fetch_object($result)) { if ($record->total >= 20) { $vn = $record->num / $record->total * 100; $vmin = 0; for ($i = 1; $i < 10; $i++) { if ($adata[$vmin][1] > $adata[$i][1]) { $vmin = $i; } } if ($vn > $adata[$vmin][1]) { $adata[$vmin][0] = $record->zone_id; $adata[$vmin][1] = $vn; } } } for ($i = 0; $i < 10; $i++) { if ($adata[$i][1] != 0) { $avalue[$adata[$i][0]] = $adata[$i][1]; } } arsort($avalue); foreach ($avalue as $key => $value) { if ($value != 0) { $data[] = array(substr(guifi_get_zone_name($key), 0, 20) . " �", $value); } } $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->SetXTickIncrement(1); $plot->SetSkipBottomTick(TRUE); $plot->SetSkipLeftTick(TRUE); $plot->SetTickLength(0); //$plot->SetXTickPos('none'); $plot->SetYDataLabelPos('plotin'); $plot->SetYLabelType('data', 0); $plot->SetTickColor('grey'); $plot->SetTTFPath($gDirTTFfonts); $plot->SetFontTTF('title', 'Vera.ttf', 12); $plot->SetFontTTF('x_label', 'Vera.ttf', 8); if (isset($_GET['title'])) { $plot->SetTitle("guifi.net \n" . t($_GET['title'])); } else { if ($zone_id == "0") { $plot->SetTitle("guifi.net \n" . t('Largest annual increase')); } else { $plot->SetTitle("guifi.net " . t('zone') . ": " . guifi_get_zone_name($zone_id) . "\n" . t('Largest annual increase')); } } //$plot->SetXTitle(t('Zones')); $plot->SetYTitle(t('% increase')); $plot->SetXDataLabelPos('plotdown'); //$plot->SetXLabelAngle(45); $plot->SetXDataLabelAngle(75); $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(); }
# case 2 : Hide Y axis only # case 3 : Hide X and Y axis lines # case 4 : Hide X and Y axis lines and maximize plot area usage. if (!isset($case)) { $case = 0; } $data = array(array('A', 1, 2), array('B', 2, 3), array('C', 3, 4), array('D', 4, 3), array('E', 3, 1)); $p = new PHPlot(); $p->SetDataType('text-data'); $p->SetDataValues($data); $p->SetPlotType('bars'); $p->SetTitle("Test axis suppression - case {$case}"); $p->SetXTickPos('none'); $p->SetXTickLabelPos('none'); $p->SetXDataLabelPos('none'); $p->SetYTickPos('none'); $p->SetYTickLabelPos('none'); $p->SetPlotBorderType('none'); $p->SetDrawXGrid(False); $p->SetDrawYGrid(False); if ($case == 1 || $case == 3 || $case == 4) { $p->SetDrawXAxis(FALSE); } if ($case == 2 || $case == 3 || $case == 4) { $p->SetDrawYAxis(FALSE); } if ($case == 4) { $p->SetMarginsPixels(2, 2, 2, 2); } // L R T B $p->DrawGraph();
$stat['data'] = array(array(NULL, NULL)); } elseif (count($stat['data'][0]) == 1) { $stat['data'][0][] = 0; } foreach ($plot_defaults as $key => $value) { if (!isset($stat[$key])) { $stat[$key] = $value; } } //Define the object $graph = new PHPlot($stat['xsize'], $stat['ysize']); $graph->SetDataType($stat['data_type']); $graph->SetFileFormat($stat['file_format']); $graph->SetPlotType($stat['graphtype']); $graph->SetDefaultTTFont('../tagsets/fonts/FreeSerif.ttf'); $graph->SetPlotBorderType('none'); // plotleft, plotright, both, full, none $graph->SetBackgroundColor($stat['background_color']); if ($stat['graphtype'] == 'bars') { $graph->SetShading(0); $graph->SetPlotAreaWorld(NULL, 0); } if (count($stat['legend']) > 0) { foreach ($stat['legend'] as $key => $val) { if (strlen($val) > 23) { $stat['legend'][$key] = substr($val, 0, 20) . '...'; } } $graph->SetLegend($stat['legend']); } if ($stat['legend_x'] && $stat['legend_y']) {
if (!empty($plot_margins)) { call_user_func_array(array($plot, 'SetMarginsPixels'), $plot_margins); } # Font setup if (!empty($ttfonts)) { if (isset($font_size)) { $plot->SetFontTTF('generic', $phplot_test_ttfonts['sans'], $font_size); } else { $plot->SetFontTTF('generic', $phplot_test_ttfonts['sans']); } } elseif (isset($font_size)) { $plot->SetFontGD('generic', $font_size); } $plot->SetTitle($title); if (!empty($plot_border)) { $plot->SetPlotBorderType($plot_border); } if (isset($pie_diam_factor)) { $plot->pie_diam_factor = $pie_diam_factor; } if (isset($shading)) { $plot->SetShading($shading); } if (isset($label_pos)) { $plot->SetLabelScalePosition($label_pos); } # For backward compatibility testing: if (isset($precision_y)) { $plot->SetPrecisionY($precision_y); } if (!empty($pie_label_args)) {
} else { $title .= $tp['ibcolor']; } $title .= ', Width: '; if (empty($tp['ibwidth'])) { $title .= '(default)'; } else { $title .= $tp['ibwidth']; } $p->SetTitle($title); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetDrawXGrid(False); $p->SetDrawYGrid(False); if (!empty($tp['plotborder'])) { $p->SetPlotBorderType($tp['plotborder']); } if (!empty($tp['pbcolor'])) { $p->SetGridColor($tp['pbcolor']); } if (!empty($tp['imageborder'])) { $p->SetImageBorderType($tp['imageborder']); } if (!empty($tp['ibcolor'])) { $p->SetImageBorderColor($tp['ibcolor']); } if (!empty($tp['ibwidth'])) { $p->SetImageBorderWidth($tp['ibwidth']); } # Move Y axis in so affect of plot area borders is more visible: $p->SetYAxisPosition(0);
include "/usr/lib/phplot/phplot.php"; include "/usr/lib/phplot/rgb.inc.php"; include "/tmp/plot.data.php"; // Test data //$cvs_data = array( // array( "", "2000/03/15", 750), // array("", "2010/04/18", 1700), // array("", "2015/05/19", 2000), // array("", "2030/06/20", 400) // ); $graph = new PHPlot(238, 220); $graph->SetIsInline("1"); $graph->SetDataType("text-data"); $graph->SetPlotType("bars"); $graph->SetDataValues($cvs_data); // Specify plotting area details $graph->SetImageArea(238, 220); $graph->SetPlotAreaPixels(55, 20, 208, 190); $graph->SetPrecisionY("0"); $graph->SetVertTickIncrement("100"); $graph->SetTickLength("5"); $graph->SetTitleFontSize("2"); $graph->SetPlotBgColor(204, 204, 204); $graph->SetPlotBorderType("left"); $graph->SetBackgroundColor($ColorArray["gray80"]); // Define the X axis $graph->SetXLabel("Date"); // Define the Y axis $graph->SetDataColors(array("blue", "red"), array("black")); $graph->SetFileFormat("png"); $graph->DrawGraph();