function draw_graph($example_data, $attribute) { require_once 'phplot.php'; $plot = new PHPlot_truecolor(800, 800); $plot->SetTitle('Distribution of ' . $attribute); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetDataValues($example_data); $plot->SetPlotType('linepoints'); $plot->SetDrawYDataLabelLines(True); $plot->SetXTitle("Selected Dates"); $plot->SetYTitle($attribute); $plot->DrawGraph(); }
mt_srand(1); $data = array(); $value = 10; for ($i = 0; $i < 500; $i++) { $data[] = array('', $i, $value); $value = max(0, $value + mt_rand(-9, 10)); } # Make a color gradient array of blue: $colors = array(); for ($b = 32; $b <= 255; $b += 2) { $colors[] = array(0, 0, $b); } for ($b = 255; $b >= 32; $b -= 2) { $colors[] = array(0, 0, $b); } # Use a truecolor plot image in order to get more colors. $plot = new PHPlot_truecolor(800, 600); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetPlotType('thinbarline'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetLineWidths(2); $plot->SetDataColors($colors); $plot->SetXTickPos('none'); $plot->SetPlotAreaWorld(0, 0, 500, NULL); $plot->SetTitle('Meaningless Data with Color Gradient'); # Establish the function 'getcolor' as a data color selection callback. $plot->SetCallback('data_color', 'getcolor'); $plot->DrawGraph();
} // Shading, empty string to omit if (!isset($alpha)) { $alpha = 50; } // Default data colors alpha, NULL to skip require_once 'phplot.php'; $data = array(); for ($i = 0; $i < 16; $i++) { $data[] = array('', 1); } $p = new PHPlot_truecolor(800, 800); if ($shading === '') { $d_shading = "default shading"; } elseif ($shading === 0) { $d_shading = "no shading"; } else { $d_shading = "shading={$shading}"; } $p->SetTitle("Truecolor Piechart with alpha={$alpha}, {$d_shading}"); $p->SetDataType('text-data-single'); $p->SetDataValues($data); if (isset($alpha)) { $p->SetDataColors(NULL, NULL, $alpha); } $p->SetPlotType('pie'); if ($shading !== '') { $p->SetShading($shading); } $p->DrawGraph();
function plot_histogram($image_filename, $param) { extract($param); $histo = get_histogram($image_filename); if (empty($histo)) { return; } for ($i = 0; $i < 256; $i++) { $data[$i] = array('', $histo[$i]); } $p = new PHPlot_truecolor($plot_image_width, $plot_image_height); $p->SetFileFormat('jpg'); $p->SetBgImage($image_filename, 'scale'); $p->SetDataType('text-data'); $p->SetDrawXAxis(False); $p->SetDrawYAxis(False); $p->SetDataValues($data); $p->SetXDataLabelPos('none'); $p->SetXTickLabelPos('none'); $p->SetYTickLabelPos('none'); $p->SetXTickPos('none'); $p->SetYTickPos('none'); $p->SetDrawYGrid(False); $p->SetDataColors($histogram_color, NULL, $histogram_alpha); $p->SetPlotType('thinbarline'); if ($draw_border) { $p->SetGridColor($border_color); $p->SetPlotBorderType('full'); } else { $p->SetPlotBorderType('none'); } # Compute the position of the histogram plot within the image. $hx0 = (int) ($hx * $plot_image_width); $hy0 = (int) ($hy * $plot_image_height); $hx1 = (int) ($h_width * $plot_image_width) + $hx0; $hy1 = (int) ($h_height * $plot_image_height) + $hy0; $p->SetPlotAreaPixels($hx0, $hy0, $hx1, $hy1); $p->DrawGraph(); }