public function renderLot() { $grafico = new PHPlot(800, 600); $grafico->SetFileFormat("jpg"); $grafico->SetIsInline(True); #Indicamos o títul do gráfico e o título dos dados no eixo X e Y do mesmo $grafico->SetTitle($this->data->titulo); $grafico->SetXTitle($this->data->eixoX); $grafico->SetYTitle($this->data->eixoY); #passamos o tipo de gráfico escolhido if (!$this->data->tipoLot) { $this->data->tipoLot = 'bars'; } $grafico->SetPlotType($this->data->tipoLot); switch ($this->data->tipoLot) { case 'pie': $grafico->SetPieLabelType('index', 'custom', 'mycallback'); $grafico->SetDataType('text-data-single'); break; case 'stackedbars': $grafico->SetDataType('text-data-yx'); break; case 'bubbles': $grafico->SetDataType('data-data-xyz'); break; } $grafico->SetLegend($column_names); #Definimos os dados do gráfico switch ($this->data->tipoLot) { case 'pie': $dados = array(array($this->data->x1, $this->data->y11), array($this->data->x2, $this->data->y21), array($this->data->x3, $this->data->y31), array($this->data->x4, $this->data->y41)); break; default: $dados = array(array($this->data->x1, $this->data->y11, $this->data->y12, $this->data->y13), array($this->data->x2, $this->data->y21, $this->data->y22, $this->data->y23), array($this->data->x3, $this->data->y31, $this->data->y32, $this->data->y33), array($this->data->x4, $this->data->y41, $this->data->y42, $this->data->y43)); break; } $grafico->SetDataValues($dados); #Salvamos o gráfico $caminho = \Manager::getFilesPath(); $fileName = uniqid() . '.jpg'; $grafico->SetOutputFile($caminho . '/' . $fileName); $grafico->SetIsInline(True); $grafico->DrawGraph(); #obtemos o endereco do grafico $this->data->locate = \Manager::getDownloadURL('files', basename($fileName), true); }
<?php # PHPlot Example: Pie Chart Label Types - Multi-part labels # This requires PHPlot >= 5.6.0 require_once 'phplot.php'; require_once 'pielabeltypedata.php'; // Defines $data and $title function mycallback($str) { list($percent, $label) = explode(' ', $str, 2); return sprintf('%s (%.1f%%)', $label, $percent); } $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetPlotType('pie'); $plot->SetDataType('text-data-single'); $plot->SetDataValues($data); $plot->SetTitle($title); # Set label type: combine 2 fields and pass to custom formatting function $plot->SetPieLabelType(array('percent', 'label'), 'custom', 'mycallback'); $plot->DrawGraph();
$legend[] = $row[0] . ' = ' . $row[1]; } # 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);
<?php # $Id$ # PHPlot Example: Pie Chart Label Types - Labels from data array # This requires PHPlot >= 5.6.0 require_once 'phplot.php'; require_once 'ex-pielabeltypedata.php'; // Defines $data and $title $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetPlotType('pie'); $plot->SetDataType('text-data-single'); $plot->SetDataValues($data); $plot->SetTitle($title); # Set label type: Use labels from data array $plot->SetPieLabelType('label'); $plot->DrawGraph();
<?php # PHPlot Example: Pie Chart Label Types - Index and custom callback # This requires PHPlot >= 5.6.0 require_once 'phplot.php'; require_once 'pielabeltypedata.php'; // Defines $data and $title $mylabels = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'); function mycallback($index) { global $mylabels; return $mylabels[$index]; } $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetPlotType('pie'); $plot->SetDataType('text-data-single'); $plot->SetDataValues($data); $plot->SetTitle($title); # Set label type: Pass segment index (0-N) to custom formating function $plot->SetPieLabelType('index', 'custom', 'mycallback'); $plot->DrawGraph();
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']) { $graph->SetLegendPixels($stat['legend_x'], $stat['legend_y']); } if ($stat['graphtype'] == 'pie') { $graph->SetPlotAreaPixels(150, 0, $stat['xsize'], $stat['ysize']); $graph->SetLegendPixels(1, 30); $graph->SetShading(0); if ($stype == 'experience_avg_experimentclass') { $graph->SetPieLabelType('value'); } } $graph->SetTitle($stat['title']); if ($stat['xtitle']) { $graph->SetXTitle($stat['xtitle'], 'plotdown'); } // plotup, plotdown, both, none if ($stat['ytitle']) { $graph->SetYTitle($stat['ytitle'], 'plotleft'); } // plotleft, plotright, both, plotin, none // Remember that angles other than 90 are taken as 0 when working with fixed fonts. if (isset($stat['x_label_angle'])) { $graph->SetXLabelAngle($stat['x_label_angle']); } else {
# case 2) GridColor set, PieLabelColor set. Labels use PieLabelColor. # For post-5.6.0 with new color control function. require_once 'phplot.php'; if (empty($case)) { $case = 0; } $colors = array('grid' => 'green', 'pielabel' => 'blue'); $data = array(array('Baseball', 100), array('Football', 85), array('Basketball', 53), array('Hockey', 48)); $plot = new PHPlot(800, 600); $plot->SetDataType('text-data-single'); $plot->SetDataValues($data); $plot->SetPlotType('pie'); $title = "Pie Chart Label Color\n"; if ($case == 1 || $case == 2) { $plot->SetGridColor($colors['grid']); $title .= "GridColor set to {$colors['grid']}\n"; } else { $title .= "GridColor is NOT set\n"; } if ($case == 2) { $plot->SetPieLabelColor($colors['pielabel']); $title .= "PieLabelColor set to {$colors['pielabel']}\n"; } else { $title .= "PieLabelColor is NOT set\n"; } $plot->SetPieLabelType(array('label', 'value')); foreach ($data as $row) { $plot->SetLegend($row[0]); } $plot->SetTitle($title); $plot->DrawGraph();
$title = "Start @{$start_angle}d {$direction}"; $plot->SetCallback('draw_all', 'draw_plot_title', array($plot, $xbase + 100, $ybase + 200, $title)); $plot->DrawGraph(); } # Make a data array with equal-size slices: $data = array_fill(0, $pie_slices, array('', 1)); $plot = new PHPlot(800, 600); $plot->SetDataValues($data); $plot->SetDataType('text-data-single'); $plot->SetPlotType('pie'); $plot->SetShading(0); $plot->SetImageBorderType('plain'); $plot->SetPrintImage(False); $plot->SetTitle("Pie Chart - Vary Start Angle and Direction\n" . "(CW = Clockwise, CCW = Counter-clockwise)"); # Configure pie labels: Show sector index, inside the pie, in a large font. $plot->SetPieLabelType('index'); $plot->SetLabelScalePosition(0.25); # Use the default TrueType font at 36 points. $plot->SetFontTTF('generic', '', 36); # This font is used by the callback to label each plot: # Use the default TrueType font at 16 points. $plot->SetFontTTF('x_title', '', 16); // Use the default TTF font at 16 pts # Draw the plot tiles: draw_plot($plot, $base_angle + 0, 'CCW', 0, 50); draw_plot($plot, $base_angle + 90, 'CCW', 200, 50); draw_plot($plot, $base_angle + 180, 'CCW', 400, 50); draw_plot($plot, $base_angle + 270, 'CCW', 600, 50); draw_plot($plot, $base_angle + 0, 'CW', 0, 300); draw_plot($plot, $base_angle + 90, 'CW', 200, 300); draw_plot($plot, $base_angle + 180, 'CW', 400, 300);
<?php # PHPlot Example: Pie Chart Label Types - Formatted values as labels # This requires PHPlot >= 5.6.0 require_once 'phplot.php'; require_once 'pielabeltypedata.php'; // Defines $data and $title $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetPlotType('pie'); $plot->SetDataType('text-data-single'); $plot->SetDataValues($data); $plot->SetTitle($title); # Set label type: segment values, formatted with 2 decimal places $plot->SetPieLabelType('value', 'data', 2); $plot->DrawGraph();