$data2[] = array('', $data1[$i][1], ($data1[$i][2] + $data1[$i][3]) / 2); } $p = new PHPlot(800, 600); $p->SetPrintImage(0); // Do not output image until told // First plot: $p->SetDataValues($data1); $p->SetDataType('text-data'); $p->SetPlotType('ohlc'); $p->SetPlotAreaWorld(NULL, 0); // For Y to start at 0 $p->SetXTickPos('none'); $p->SetTitle('OHLC and Line Plot Overlay'); $p->SetXTitle('Date', 'plotdown'); $p->SetYTitle('Security Price', 'plotleft'); $p->SetDrawPlotAreaBackground(True); $p->SetPlotBgColor('PeachPuff'); $p->SetMarginsPixels(50, 50, 50, 50); $p->DrawGraph(); // Second plot: $p->SetDrawPlotAreaBackground(False); $p->SetDataValues($data2); $p->SetDataType('text-data'); $p->SetPlotType('lines'); $p->SetDataColors(array('red', 'orange')); // Must clear X and Y titles or they are drawn again, possibly with offset. $p->SetXTitle(''); $p->SetYTitle(''); $p->DrawGraph(); // Now output the completed image $p->PrintImage();
} # 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('PHPlot Customer Satisfaction (estimated)'); # Select the data array representation and store the data: $p->SetDataType('text-data'); $p->SetDataValues($data); # Select the plot type - bar chart: $p->SetPlotType('bars'); # Define the data range. PHPlot can do this automatically, but not as well. $p->SetPlotAreaWorld(0, 0, 9, 100); # 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('Features', 'Bugs', 'Happy Users')); $p->SetLegendWorld(0.1, 95); # Turn data labels on, and all ticks and tick labels off: $p->SetXDataLabelPos('plotdown'); $p->SetXTickPos('none'); $p->SetXTickLabelPos('none'); $p->SetYTickPos('none'); $p->SetYTickLabelPos('none'); # Generate and output the graph now: $p->DrawGraph();
<?php session_start(); require_once 'phplot.php'; echo $_GET[countKeywords]; $data = array(array('新增文件', intval($_GET[countnew])), array('删除文件', intval($_GET[countdel])), array('修改文件', intval($_GET[countmodify]))); $plot = new PHPlot(350, 280); $plot->SetTTFPath('./public'); $plot->SetDefaultTTFont('SIMHEI.TTF'); $plot->SetUseTTF(True); $plot->SetImageBorderType('plain'); $plot->SetPlotType('bars'); $plot->SetDataType('text-data'); $plot->SetPlotBorderType('full'); $plot->SetBackgroundColor('#ffffcc'); $plot->SetDrawPlotAreaBackground(True); $plot->SetPlotBgColor('#ffffff'); $plot->SetDataValues($data); $plot->SetTitle("新增文件数:{$_GET['countnew']} 删除文件数:{$_GET['countdel']} 修改文件数:{$_GET['countmodify']}"); $plot->SetTitleColor('#D9773A'); foreach ($data as $row) { $plot->Setshading(10); } $plot->SetDataBorderColors('black'); $plot->DrawGraph();
} # Common setup for all plots on the image: $plot = new PHPlot(800, 625); $plot->SetTitle('Multiple pie charts'); $plot->SetPrintImage(False); $plot->SetBackgroundColor('wheat'); $plot->SetDrawPlotAreaBackground(True); $plot->SetPlotType('pie'); $plot->SetDataType($data_type); $plot->SetDataValues($data); $plot->SetPlotBorderType('full'); #$plot->SetLabelScalePosition(0.50); # Plot 1 - upper left $plot->SetPlotAreaPixels(4, 25, 398, 323); $plot->SetPieLabelType('label'); $plot->SetPlotBgColor('plum'); $plot->DrawGraph(); # Plot 2 - upper right $plot->SetPlotAreaPixels(402, 25, 797, 323); $plot->SetPieLabelType('index'); $plot->SetPlotBgColor('salmon'); $plot->DrawGraph(); # Plot 3 - lower left $plot->SetPlotAreaPixels(4, 327, 398, 623); $plot->SetPieLabelType(''); // Reset to default $plot->SetDrawPlotAreaBackground(False); $plot->DrawGraph(); # Plot 4 - lower right $plot->SetPlotAreaPixels(402, 327, 797, 623); $plot->SetPieLabelType('value');
<?php require 'phplot/phplot.php'; require 'mem_image.php'; $graph = new PHPlot(500, 300); $graph->SetDataType('data-data'); //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->SetMarginsPixels(null, null, 40, null); $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->SetXTickIncrement(5); //Define the Y axis $graph->SetYTickIncrement(500); $graph->SetPrecisionY(0); $graph->SetLightGridColor('blue'); //Disable image output $graph->SetPrintImage(false); //Draw the graph $graph->DrawGraph(); $pdf = new PDF_MemImage();
} } } else { for ($j = 0; $j < $ny; $j++) { $widths[$j] = $j + 1; } } } if ($set_styles) { // $p->SetDefaultDashedStyle('10-5'); $p->SetDrawYGrid(False); // Hard to see dashed lines with dashed grid. } // Always do SetLineStyles (if set_styles is false, it sets them all to solid) $p->SetLineStyles($styles); if ($set_linewidths) { $p->SetLineWidths($widths); } $p->SetLegend($legend); $p->SetLegendPosition(0, 0, 'plot', 0, 0, 5, 5); if ($legend_use_shapes) { $p->SetLegendUseShapes(True); } $p->SetPlotBgColor('black'); if ($plot_area_background) { $p->SetDrawPlotAreaBackground(True); } if (isset($colorbox_width)) { $p->legend_colorbox_width = $colorbox_width; } $p->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();
} # Create a PHPlot object which will make a 600x400 pixel image: $p = new PHPlot(850, 300); # Use TrueType fonts: $p->SetDefaultTTFont('phplot/simsun.ttc'); # Set the main plot title: $p->SetTitle('版本非PASS测试例数量直方图'); # Select the data array representation and store the data: $p->SetDataType('text-data'); $p->SetDataValues($data); # Select the plot type - bar chart: $p->SetPlotType('bars'); # Define the data range. PHPlot can do this automatically, but not as well. //$p->SetPlotAreaWorld(0, 0, 7, 100); # Select an overall image background color and another color under the plot: $p->SetBackgroundColor('#CCDDED'); $p->SetDrawPlotAreaBackground(True); $p->SetPlotBgColor('#CCDDED'); # 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('No Pass')); $p->SetLegendWorld(0.1, 95); # Turn data labels on, and all ticks and tick labels off: $p->SetXDataLabelPos('plotdown'); $p->SetXTickPos('none'); $p->SetXTickLabelPos('none'); $p->SetYTickPos('none'); $p->SetYTickLabelPos('none'); # Generate and output the graph now: $p->DrawGraph();
<?php # $Id$ # Testing phplot - Fix for SetPlotAreaPixels with pie charts. require_once 'phplot.php'; $data = array(); $legend = array(); for ($i = 0; $i < 15; $i++) { $data[] = array('', 10 + $i); $legend[] = "A very long label for set {$i}"; } $p = new PHPlot(800, 500); $p->SetPlotAreaPixels(240, 20, 795, 495); $p->SetLegendPixels(5, 40); $p->SetLegend($legend); $p->SetTitle("Pie chart, SetPlotAreaPixels, Long Labels"); $p->SetDataType('text-data-single'); $p->SetDataValues($data); $p->SetPlotType('pie'); # Color background so we can see what's what: $p->SetDrawPlotAreaBackground(True); $p->SetPlotBgColor('gray'); $p->DrawGraph();
if (isset($labels[(int) $value])) { return $labels[(int) $value]; } return $value; } # <=12 13-17 17-28 30-39 40-54 >=55 $data = array(array('Cherry', 1, 1, 2, 2, 4, 3, 3, 4, 3, 5, 5, 6, 6), array('Apple', 2, 1, 9, 2, 7, 3, 4, 4, 7, 5, 3, 6, 7), array('Pear', 3, '', 2, 2, 2, 3, 3, 4, 4, 5, 3, 6, 2), array('Grape', 4, 1, 8, 2, 5, 3, 5, 4, 6, 5, 3, 6, 4), array('Kiwi', 5, '', 0, 2, 3, 3, 4, 4, 4, 5, 5, 6, 2), array('Banana', 6, 1, 5, 2, 4, 3, 6, 4, 3, 5, 3, 6, 4)); $plot = new PHPlot(600, 600); $plot->SetTitle("Flavor Preference By Age Group"); $plot->SetDataType('data-data-xyz'); $plot->SetDataValues($data); $plot->SetPlotType('bubbles'); $plot->SetDataColors('yellow'); // Use same color for all data sets $plot->SetDrawPlotAreaBackground(True); $plot->SetPlotBgColor('plum'); $plot->SetLightGridColor('red'); // Change grid color to make it visible $plot->SetImageBorderType('plain'); $plot->SetPlotBorderType('full'); $plot->SetXTickIncrement(1); // For grid line spacing $plot->SetYTickIncrement(1); $plot->SetPlotAreaWorld(0, 0, 6.5, 6.5); # Establish the handler for the Y label text: $plot->SetYLabelType('custom', 'get_label', $y_labels); $plot->SetXTickPos('both'); // Tick marks on both sides $plot->SetYTickPos('both'); // Tick marks on top and bottom too $plot->SetXDataLabelPos('both');
for ($v = 1, $i = 0; $i < $n_slices; $i++, $v *= 1.414) { $data[] = array('', $v); } # Build a title: $title = 'Pie Autosize Test: Label scale pos=' . (isset($label_pos) ? $label_pos : "not set") . ', Autosize is '; # Detect presence of autosize feature (PHPlot>=5.6.0): $do_autosize = method_exists('PHPlot', 'SetPieAutoSize'); if (!$do_autosize) { $title .= "(not available).\n" . "Pie should be sized right up to plot area edge."; } elseif ($pie_autosize) { $title .= "On.\n" . "Pie should be sized so labels are contained in plot area."; } else { $title .= "Off.\n" . "Pie should be sized just inside (5px) of plot area."; } $plot = new PHPlot(800, 600); $plot->SetPlotType('pie'); $plot->SetDataType('text-data-single'); $plot->SetDataValues($data); $plot->SetTitle($title); $plot->SetMarginsPixels(50, 50, 50, 50); $plot->SetShading(0); if (isset($label_pos)) { $plot->SetLabelScalePosition($label_pos); } // Turn on plot area background to make margins visible. $plot->SetPlotBgColor('gray'); $plot->SetDrawPlotAreaBackground(TRUE); if ($do_autosize) { $plot->SetPieAutoSize($pie_autosize); } $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(); }
$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); } $p->SetLegendUseShapes($use_shapes); if (!empty($text_color)) { $p->SetTextColor($text_color); } if (!empty($legend_text_color)) { $p->SetLegendTextColor($legend_text_color); } $p->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();