connect(); $sql = "SELECT data,COUNT(data) as total FROM criacao_literaria.historico \r\n\t\twhere acao='login' \r\n\t\tGROUP BY data \r\n\t\tORDER BY data desc\r\n\t\tLIMIT 12;"; $Resultado = mysql_query($sql) or die("Erro: " . mysql_error()); $i = 0; $data = array(); while ($array_exibir = mysql_fetch_array($Resultado)) { $data[] = array($array_exibir['data'], $array_exibir['total']); $i++; } # Create a PHPlot object which will make an 800x400 pixel image: $p = new PHPlot(800, 400); # Use TrueType fonts: //$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'));
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();
# Y2 = cos(x) $end = M_PI * 2.0; $delta = $end / 20.0; $data = array(); for ($x = 0; $x <= $end; $x += $delta) { $data[] = array('', $x, sin($x), cos($x)); } $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); $plot->SetPlotType('lines'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); # Main plot title: $plot->SetTitle('Line Plot, Sin and Cos'); # Make a legend for the 2 functions: $plot->SetLegend(array('sin(t)', 'cos(t)')); # Select a plot area and force ticks to nice values: $plot->SetPlotAreaWorld(0, -1, 6.8, 1); # Even though the data labels are empty, with numeric formatting they # will be output as zeros unless we turn them off: $plot->SetXDataLabelPos('none'); $plot->SetXTickIncrement(M_PI / 8.0); $plot->SetXLabelType('data'); $plot->SetPrecisionX(3); $plot->SetYTickIncrement(0.2); $plot->SetYLabelType('data'); $plot->SetPrecisionY(1); # Draw both grids: $plot->SetDrawXGrid(True); $plot->SetDrawYGrid(True); $plot->DrawGraph();
$row = array("={$grp}="); for ($bar = 1; $bar <= $tp['nbars']; $bar++) { $row[] = floor($x + 0.5); $tx = $x * $cdt - $y * $sdt; $y = $x * $sdt + $y * $cdt; $x = $tx; } $data[] = $row; } } $p = new PHPlot(800, 600); $p->SetTitle($tp['title'] . $tp['suffix']); $p->SetDataType('text-data'); $p->SetDataValues($data); # Options: # Note: <=5.0rc3 used x_label font. This was corrected. if (isset($tp['fontsize'])) { $p->SetFont('y_label', $tp['fontsize']); } if (isset($tp['shading'])) { $p->SetShading($tp['shading']); } # Note: This didn't work <= 5.0rc3 if (isset($tp['yprec'])) { $p->SetPrecisionY($tp['yprec']); } $p->SetXTickLabelPos('none'); $p->SetXTickPos('none'); $p->SetYDataLabelPos('plotin'); $p->SetPlotType('bars'); $p->DrawGraph();
<?php # $Id$ # Testing phplot: label format require_once 'phplot.php'; $data = array(array('', -1000, 1000), array('', -500, 23456), array('', 0, 800), array('', 500, 234100), array('', 1000, 1234567), array('', 1500, 100000), array('', 2000, 1901000), array('', 2500, 999999)); $plot = new PHPlot(); $plot->SetPlotType('lines'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); # Main plot title: $plot->SetTitle('Number formatted labels'); # Select a plot area and force ticks to nice values: $plot->SetPlotAreaWorld(-1000, 0); # Even though the data labels are empty, with numeric formatting they # will be output as zeros unless we turn them off: $plot->SetXDataLabelPos('none'); $plot->SetXTickIncrement(500); $plot->SetXLabelType('data'); $plot->SetPrecisionX(0); $plot->SetYTickIncrement(200000); $plot->SetYLabelType('data'); $plot->SetPrecisionY(2); $plot->SetDrawXGrid(False); $plot->SetDrawYGrid(False); # HACK #$plot->decimal_point = ','; #$plot->thousands_sep = ''; $plot->DrawGraph();
$graph = new PHPlot(500, 250); $graph->SetDataType('linear-linear'); //Specify some data $data = array(array('', 2000, 750), array('', 2010, 1700), array('', 2015, 2000), array('', 2020, 1800), array('', 2025, 1300), array('', 2030, 400)); $graph->SetDataValues($data); //Specify plotting area details $graph->SetPlotType('lines'); $graph->SetTitleFontSize('2'); $graph->SetTitle('Social Security trust fund asset estimates, in $ billions'); $graph->SetPlotAreaWorld(2000, 0, 2035, 2000); $graph->SetPlotBgColor('white'); $graph->SetPlotBorderType('left'); $graph->SetBackgroundColor('white'); $graph->SetDataColors(array('red'), array('black')); //Define the X axis $graph->SetXLabel('Year'); $graph->SetHorizTickIncrement('5'); $graph->SetXGridLabelType('default'); //Define the Y axis $graph->SetVertTickIncrement('500'); $graph->SetPrecisionY('0'); $graph->SetYGridLabelType('right'); $graph->SetLightGridColor('blue'); //Disable image output $graph->SetPrintImage(0); //Draw the graph $graph->DrawGraph(); //$pdf = new MEM_IMAGE(); //$pdf->AddPage(); //$pdf->GDImage($graph->PrintImage(),30,20,140); //$pdf->Output();
<?php # PHPlot Example: Bar chart, annual data require_once 'phplot.php'; $data = array(array('1985', 340), array('1986', 682), array('1987', 1231), array('1988', 2069), array('1989', 3509), array('1990', 5283), array('1991', 7557), array('1992', 11033), array('1993', 16009), array('1994', 24134), array('1995', 33768), array('1996', 44043), array('1997', 55312), array('1998', 69209), array('1999', 86047), array('2000', 109478), array('2001', 128375), array('2002', 140767)); $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); $plot->SetPlotType('bars'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); # Let's use a new color for these bars: $plot->SetDataColors('magenta'); # Force bottom to Y=0 and set reasonable tick interval: $plot->SetPlotAreaWorld(NULL, 0, NULL, NULL); $plot->SetYTickIncrement(10000); # Format the Y tick labels as numerics to get thousands separators: $plot->SetYLabelType('data'); $plot->SetPrecisionY(0); # Main plot title: $plot->SetTitle('US Cell Phone Subscribership'); # Y Axis title: $plot->SetYTitle('Thousands of Subscribers'); # Turn off X tick labels and ticks because they don't apply here: $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); $plot->DrawGraph();
} else { $graph->SetYTitle(_('Quantity')); } $graph->SetXTickPos('none'); $graph->SetXTickLabelPos('none'); $graph->SetXLabelAngle(90); $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'); $graph->SetNumberFormat($DecimalPoint, $ThousandsSeparator); $graph->SetPrecisionY($_SESSION['CompanyRecord']['decimalplaces']); $SalesResult = DB_query($SQL); if (DB_error_no() != 0) { prnMsg(_('The sales graph data for the selected criteria could not be retrieved because') . ' - ' . DB_error_msg(), '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; } $GraphArray = array(); $i = 0; while ($myrow = DB_fetch_array($SalesResult)) { $GraphArray[$i] = array(MonthAndYearFromSQLDate($myrow['lastdate_in_period']), $myrow['sales'], $myrow['budget']);
} 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)) { call_user_func_array(array($plot, 'SetPieLabelType'), $pie_label_args); } // For test using colors as labels: if (!empty($data_colors)) { $plot->SetDataColors($data_colors); } $plot->DrawGraph();
/** * drawing the graph for a evaluation question * * @param array() $data * @param string $evalquestion_id */ function do_graph($data, $evalquestion_id) { global $tmp_path_export, $auth, $PATH_EXPORT; $type = do_graph_template(); //Define the object if ($type == "pie") { // Beim pie muss die Zeichenflaeche etwas groesser gewaehlt werden... $graph = new PHPlot(500, 300); } else { $graph = new PHPlot(300, 250); } if ($type == "pie") { // Beim pie muss das Array umgeformt werden. Bug in PHPlot? $tmp = array(); $tmp2 = array(); $legend = array(); array_push($tmp, "Test"); foreach ($data as $k => $d) { array_push($tmp, $d[1]); array_push($legend, $d[0]); } array_push($tmp2, $tmp); $data = $tmp2; $graph->SetLegend($legend); } //Data Colors $graph->SetDataColors(array("blue", "green", "yellow", "red", "PeachPuff", "orange", "pink", "lavender", "navy", "peru", "salmon", "maroon", "magenta", "orchid", "ivory"), array("black")); $max_x = max(array_map('next', $data)); $graph->SetPlotAreaWorld(NULL, 0); // y-achse bei 0 starten $graph->SetPrecisionY(0); //anzahl kommastellen y-achse $graph->SetYTickIncrement($max_x < 10 ? 1 : round($max_x / 10)); $graph->SetPlotBgColor(array(222, 222, 222)); $graph->SetDataType("text-data"); $graph->SetFileFormat(Config::get()->EVAL_AUSWERTUNG_GRAPH_FORMAT); $graph->SetOutputFile($tmp_path_export . "/evalsum" . $evalquestion_id . $auth->auth["uid"] . "." . Config::get()->EVAL_AUSWERTUNG_GRAPH_FORMAT); $graph->SetIsInline(true); $graph->SetDataValues($data); $graph->SetPlotType($type); $graph->SetXLabelAngle(count($data) < 10 ? 0 : 90); //$graph->SetShading(0); // kein 3D $graph->SetLineWidth(1); $graph->SetDrawXDataLabels(true); //Draw it $graph->DrawGraph(); }
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();