/** * Gera um gráfico de linha * @param array $dados Array no formato array('Label' => array(pontos)) * @param string $tipo linha ou barra */ function grafico($dados, $tipo = 'linha') { require_once 'exemplos/graficos/pChart/class/pDraw.class.php'; require_once 'exemplos/graficos/pChart/class/pImage.class.php'; require_once 'exemplos/graficos/pChart/class/pData.class.php'; // precisamos ter dados para montar os gráficos $DataSet = new pData(); // Adicionando os pontos de um gráfico de linha // horas de trabalho na semana foreach ($dados as $label => $pontos) { $DataSet->addPoints($pontos, $label); } $DataSet->setAxisName(0, 'Horas'); // unidade $DataSet->setAxisUnit(0, 'h'); $settings = array("R" => 229, "G" => 11, "B" => 11, "Alpha" => 80); $DataSet->setPalette("Joao", $settings); // Labels $DataSet->addPoints(array('Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'), 'Dias'); $DataSet->setSerieDescription('Dias', 'Dias da Semana'); $DataSet->setAbscissa('Dias'); $Graph = new pImage(700, 230, $DataSet); $Graph->setFontProperties(array('FontName' => 'exemplos/graficos/pChart/fonts/verdana.ttf', 'FontSize' => 8)); $Graph->setGraphArea(50, 40, 670, 190); $scale = array('GridR' => 150, 'GridG' => 150, 'GridB' => 150, 'DrawSubTicks' => true, 'CycleBackground' => true); $Graph->drawScale($scale); if ($tipo == 'linha') { $Graph->drawLineChart(); } else { $Graph->drawBarChart(); } $Graph->drawLegend(540, 25, array('Style' => LEGEND_ROUND, 'Mode' => LEGEND_VERTICAL)); $Graph->drawText(60, 20, "Horas Trabalhadas"); $Graph->autoOutput(); }
/** * Desenha um gráfico de linhas * @param $title título do graico * @param $data matriz contendo as séries de dados * @param $xlabels vetor contendo os rótulos do eixo X * @param $ylabel rótulo do eixo Y * @param $width largura do gráfico * @param $height altura do gráfico * @param $outputPath caminho de saída do gráfico */ public function drawLineChart($title, $data, $xlabels, $ylabel, $width, $height, $outputPath) { // cria o modelo de dados $modelo = new pData(); foreach ($data as $legend => $serie) { $newdata = array(); foreach ($serie as $value) { $newdata[$legend][] = $value == NULL ? VOID : $value; } $modelo->addPoints($newdata[$legend], $legend); } $modelo->setAxisName(0, $ylabel); $modelo->addPoints($xlabels, "Labels"); $modelo->setAbscissa("Labels"); // cria o objeto que irá conter a imagem do gráfico $imagem = new pImage($width, $height, $modelo); // adiciona uma borda na forma de um retângulo dentro da imagem $imagem->drawRectangle(0, 0, $width - 1, $height - 1, array("R" => 0, "G" => 0, "B" => 0)); // escreve um título dentro do gráfico $imagem->setFontProperties(array("FontName" => "app/lib/pchart/fonts/Forgotte.ttf", "FontSize" => 11)); $imagem->drawText(60, 35, $title, array("FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMLEFT)); // define a fonte dos dados do gráfico $imagem->setFontProperties(array("FontName" => "app/lib/pchart/fonts/pf_arma_five.ttf", "FontSize" => 6)); // define a área do gráfico $imagem->setGraphArea(60, 40, $width - 50, $height - 30); // define a escala do gráfico $scaleSettings = array("XMargin" => 10, "YMargin" => 10, "CycleBackground" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 200); $imagem->drawScale($scaleSettings); // liga a suavização de linhas $imagem->Antialias = TRUE; // desenha o gráfico de linhas $imagem->drawLineChart(array('DisplayValues' => TRUE)); // desenha a legenda do gráfico $imagem->drawLegend(60, $height - 13, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); // grava o gráfico em um arquivo $imagem->render($outputPath); }
/** * eval_ccpc_genGraphLine - Génère un graphique de type Line simple sous forme d'image au format PNG * * @category : eval_ccpc_functions * @param array $data Données à partir desquelles le graphique est généré * @return string URL de l'image générée * * @Author Ali Bellamine * * Structure de $data :<br> * ['option'] => (array) Liste des labels disponibles<br> * ['data'][nom de la catégorie][nom du label] => (int) Valeur du label<br> * ['settings']['min'] => (int) Valeur (ordonnée) minimale<br> * ['settings']['max'] => (int) Valeur (ordonnée) maximale<br> * ['settings']['height'] => (int) Hauteur du graphique (en px)<br> * ['settings']['width'] => (int) Largeur du graphique (en px) * */ function eval_ccpc_genGraphLine($data) { // On vérifie les données fournit if (isset($data) && isset($data['data']) && count($data['data']) > 0 && isset($data['option']) && count($data['option']) > 0) { // On récupère le hash de $data $hash = md5(json_encode($data)); // Chemin du fichier $filePath = PLUGIN_PATH . 'cache/' . $hash . '.png'; $filePathURI = ROOT . 'evaluations/ccpc/cache/' . $hash . '.png'; // Si le hash existe déjà : on renvoie le lien de l'image // sinon en crée le graphique if (is_file($filePath)) { return $filePathURI; } else { // On crée l'image /* On inclut la librairie */ require_once PLUGIN_PATH . 'core/pChart2.1.4/class/pData.class.php'; require_once PLUGIN_PATH . 'core/pChart2.1.4/class/pDraw.class.php'; require_once PLUGIN_PATH . 'core/pChart2.1.4/class/pImage.class.php'; /* On crée l'objet pData */ // Préparation des données $tempDataArray = array(); // Contient les données chiffrés foreach ($data['data'] as $tempDataLegend => $tempDataValue) { if (is_array($tempDataValue)) { foreach ($data['option'] as $key) { if (isset($tempDataValue[$key]) && is_numeric($tempDataValue[$key])) { $tempDataArray[$tempDataLegend][$key] = $tempDataValue[$key]; } else { $tempDataArray[$tempDataLegend][$key] = VOID; } } } else { return FALSE; } } $MyData = new pData(); foreach ($tempDataArray as $key => $value) { $MyData->addPoints($value, $key); } $MyData->addPoints($data['option'], 'Label'); $MyData->setAbscissa("Label"); $MyData->setSerieDescription("Label", "Label"); /* On crée l'objet pChart */ if (isset($data['settings']['width'])) { $width = $data['settings']['width']; } else { $width = 600; } if (isset($data['settings']['height'])) { $height = $data['settings']['height']; } else { $height = 300; } $myPicture = new pImage($width, $height, $MyData, TRUE); $myPicture->setFontProperties(array("FontName" => PLUGIN_PATH . "core/pChart2.1.4/fonts/MankSans.ttf", "FontSize" => 14, "R" => 80, "G" => 80, "B" => 80)); // On détermine les limites $myPicture->setGraphArea(0, 0, $width, $height - 30); $scaleSettings = array("DrawSubTicks" => TRUE); if (isset($data['settings']['min']) && is_numeric($data['settings']['min']) && isset($data['settings']['max']) && is_numeric($data['settings']['max']) && $data['settings']['min'] < $data['settings']['max']) { // Prise en charge de la possibilité d'imposer le min et le max $scaleSettings['Mode'] = SCALE_MODE_MANUAL; $scaleSettings['ManualScale'][0] = array('Min' => $data['settings']['min'], 'Max' => $data['settings']['max']); // Min et Max sur l'axe des ordonnées } $myPicture->drawScale($scaleSettings); $myPicture->drawLegend(10, 10, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); $settings = array("Surrounding" => -30, "InnerSurrounding" => 30, "DisplayValues" => TRUE, "ORIENTATION_HORIZONTAL" => TRUE); $myPicture->drawLineChart($settings); $myPicture->render($filePath); return $filePathURI; } } else { return FALSE; } }
<?php include "class/pData.class.php"; include "class/pDraw.class.php"; include "class/pImage.class.php"; $myData = new pData(); $myData->addPoints(array(64, 187, 395, 249, 109, 129, 136, 133, 134, 95, 72, 85), "Serie1"); $myData->setSerieDescription("Serie1", "Serie 1"); $myData->setSerieOnAxis("Serie1", 0); $myData->addPoints(array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"), "Absissa"); $myData->setAbscissa("Absissa"); $myData->setAxisPosition(0, AXIS_POSITION_LEFT); $myData->setAxisName(0, "Rejistu sira"); $myData->setAxisUnit(0, ""); $myPicture = new pImage(700, 230, $myData); $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0)); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 20)); $myPicture->setFontProperties(array("FontName" => "fonts/Forgotte.ttf", "FontSize" => 14)); $TextSettings = array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 5, "G" => 0, "B" => 79); $myPicture->drawText(350, 25, "Andamentu Geral Rejistru Kliente", $TextSettings); $myPicture->setShadow(FALSE); $myPicture->setGraphArea(50, 50, 675, 190); $myPicture->setFontProperties(array("R" => 0, "G" => 0, "B" => 0, "FontName" => "fonts/GeosansLight.ttf", "FontSize" => 10)); $Settings = array("Pos" => SCALE_POS_LEFTRIGHT, "Mode" => SCALE_MODE_FLOATING, "LabelSkip" => 1, "LabelingMethod" => LABELING_ALL, "GridR" => 186, "GridG" => 177, "GridB" => 185, "GridAlpha" => 50, "TickR" => 240, "TickG" => 17, "TickB" => 17, "TickAlpha" => 50, "LabelRotation" => 0, "CycleBackground" => 1, "DrawXLines" => 1, "DrawYLines" => ALL); $myPicture->drawScale($Settings); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 10)); $Config = array("DisplayValues" => 1, "BreakVoid" => 0, "BreakR" => 234, "BreakG" => 55, "BreakB" => 26); $myPicture->drawLineChart($Config); $myPicture->stroke();
public function drawImage() { $qr_result = $this->values; //var_dump($qr_result);die(); $va_columns = $this->parameters["columns"]; $width = $this->parameters["width"]; $format = $this->parameters["format"]; $va_charting_columns = $this->parameters["charting_columns"]; $va_chart_types = $this->parameters["chart_types"]; $qr_result->seek(); if ($qr_result->numRows() == 0) { //if no result nothing to do return false; } // Loading chart format specifications // TODO : this coding part should be out of this function, sending values in 1 parameter if (is_array($va_chart_types)) { foreach ($va_chart_types as $type => $settings) { if ($type == $format) { $chart_type = $settings["googletype"]; $message = $settings["message"]; } } } /* Create and populate the pData object */ $MyData = new pData(); // Fulfillment of the results $va_row_no = 0; $va_content = array(); while ($qr_result->nextRow()) { $va_column_no = 0; foreach ($va_columns as $va_column => $va_column_label) { // only render columns specified in XML field charting_columns if (in_array($va_column_label, $va_charting_columns)) { $va_content[$va_column_label][$va_row_no] = $qr_result->get($va_column_label); $va_column_no++; } } $va_row_no++; } //var_dump($va_content); $va_row_no = 0; foreach ($va_charting_columns as $va_column_label) { //print "MyData->addPoints(\"".implode("\",\"",$va_content[$va_column_label])."\",\"".$va_column_label."\");<br/>"; $MyData->addPoints($va_content[$va_column_label], $va_column_label); if ($va_row_no == 0) { //print "MyData->setAbscissa(\"Labels\")<br/>"; $MyData->setAbscissa($va_column_label); } else { //print "MyData->setSerieDescription(\"".$va_column_label."\",\"".$va_column_label."\");<br/>"; $MyData->setSerieDescription($va_column_label, $va_column_label); } $va_row_no++; } /* Create the pChart object */ $myPicture = new pImage($width, $width / 2, $MyData); /* Set the common properties */ $myPicture->setFontProperties(array("FontName" => __CA_STATISTICSVIEWER_CLASS_DIR__ . "/fonts/verdana.ttf", "FontSize" => 0.014 * $width, "R" => 80, "G" => 80, "B" => 80)); $RectangleSettings = array("R" => 200, "G" => 200, "B" => 200); $myPicture->drawRectangle(1, 1, $width - 1, $width / 2 - 1, $RectangleSettings); $myPicture->setGraphArea($width / 9, $width / 10, $width * 0.75, $width * 0.4); // if not pie, draw the legend if ($format != "pie") { $myPicture->drawLegend($width * 0.8, $width * 0.05, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); } switch ($format) { case "bar": $myPicture->drawScale(array("Pos" => SCALE_POS_TOPBOTTOM, "DrawSubTicks" => FALSE, "RemoveYAxis" => TRUE, "GridAlpha" => 90, "DrawXLines" => FALSE)); $myPicture->drawBarChart(); break; case "column": $myPicture->drawScale(array("DrawSubTicks" => FALSE, "RemoveYAxis" => TRUE, "GridAlpha" => 90, "DrawXLines" => FALSE)); $myPicture->drawBarChart(); break; case "step": $myPicture->drawScale(array("DrawXLines" => FALSE, "DrawYLines" => ALL, "GridR" => 127, "GridG" => 127, "GridB" => 127)); $myPicture->drawStepChart(array("DisplayValues" => TRUE, "DisplayColor" => DISPLAY_AUTO)); break; case "area": $myPicture->drawScale(array("DrawXLines" => FALSE, "DrawYLines" => ALL, "GridR" => 127, "GridG" => 127, "GridB" => 127)); $myPicture->drawAreaChart(array("DisplayValues" => TRUE, "DisplayColor" => DISPLAY_AUTO)); break; case "pie": $PieChart = new pPie($myPicture, $MyData); $PieChart->draw2DPie(0.4 * $width, 0.25 * $width, array("WriteValues" => PIE_VALUE_PERCENTAGE, "ValueR" => 95, "ValueG" => 95, "ValueB" => 95, "ValuePadding" => 0.03 * $width, "Radius" => 0.16 * $width, "SecondPass" => TRUE, "Border" => TRUE, "Precision" => 0)); $myPicture->setShadow(FALSE); $myPicture->setFontProperties(array("FontName" => __CA_STATISTICSVIEWER_CLASS_DIR__ . "/fonts/verdana.ttf", "FontSize" => 0.018 * $width, "R" => 80, "G" => 80, "B" => 80)); $PieChart->drawPieLegend(0.8 * $width, 0.05 * $width, array("Style" => LEGEND_NOBORDER, "BoxSize" => $width / 60, "FontR" => 0, "FontG" => 0, "FontB" => 0)); break; case "line": default: $myPicture->drawScale(array("DrawXLines" => FALSE, "DrawYLines" => ALL, "GridR" => 127, "GridG" => 127, "GridB" => 127)); $myPicture->drawLineChart(array("DisplayValues" => TRUE, "DisplayColor" => DISPLAY_AUTO)); break; } /* Render the picture (choose the best way) */ $myPicture->autoOutput(); }
$myPicture->setFontProperties(array("FontName" => "pChart/fonts/Forgotte.ttf", "FontSize" => 8, "R" => 0, "G" => 0, "B" => 0)); $myPicture->drawText(15, 22, "HAL10K by intrd", array("FontSize" => 15, "Align" => TEXT_ALIGN_BOTTOMLEFT)); //$myPicture->drawText(15,22,"HAL10K by intrd",array("FontSize"=>15,"Align"=>TEXT_ALIGN_BOTTOMLEFT)); $myPicture->drawText(450, 20, "Período: " . $startdate . " - " . $enddate . "", array("FontSize" => 13, "Align" => TEXT_ALIGN_BOTTOMLEFT)); $myPicture->drawText(651, 23, $nextmov, array("FontSize" => 13, "Align" => TEXT_ALIGN_BOTTOMLEFT)); $myPicture->setFontProperties(array("FontName" => "pChart/fonts/pf_arma_five.ttf", "FontSize" => 10, "R" => 0, "G" => 0, "B" => 0)); $myPicture->setGraphArea(20 * 2, 20, 650 * 2, 200 * 2); $scaleSettings = array("XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 500, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE); $myPicture->drawScale($scaleSettings); $myPicture->Antialias = TRUE; $MyData->setSerieDrawable("BTC/USD", TRUE); $MyData->setSerieDrawable("EMAshort", TRUE); $MyData->setSerieDrawable("EMAlong", TRUE); $MyData->setSerieDrawable("Buy", FALSE); $MyData->setSerieDrawable("Sell", FALSE); $myPicture->drawLineChart(array("DisplayValues" => FALSE)); $MyData->setSerieDrawable("BTC/USD", FALSE); $MyData->setSerieDrawable("EMAshort", FALSE); $MyData->setSerieDrawable("EMAlong", FALSE); $MyData->setSerieDrawable("Buy", TRUE); $MyData->setSerieDrawable("Sell", TRUE); $myPicture->drawPlotChart(array("DisplayValues" => TRUE, "PlotBorder" => FALSE, "BorderSize" => 2, "Surrounding" => -60, "BorderAlpha" => 80)); $MyData->setSerieDrawable("BTC/USD", TRUE); $MyData->setSerieDrawable("EMAshort", TRUE); $MyData->setSerieDrawable("EMAlong", TRUE); $MyData->setSerieDrawable("Buy", TRUE); $MyData->setSerieDrawable("Sell", TRUE); //$myPicture->writeBounds(); $myPicture->drawLegend(121, 10, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL, "FontR" => 0, "FontG" => 0, "FontB" => 0)); /* $last=explode(",",end($F1)); if ($last[7]<=1) {
$MyData->setAbscissaName("Time (years)"); /* Create the pChart object */ $myPicture = new pImage(700, 230, $MyData); /* Turn of Antialiasing */ $myPicture->Antialias = FALSE; /* Draw the background and the border */ $myPicture->drawFilledRectangle(0, 0, 699, 229, array("R" => 200, "G" => 200, "B" => 200)); $myPicture->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, array("StartR" => 220, "StartG" => 220, "StartB" => 220, "EndR" => 100, "EndG" => 100, "EndB" => 100, "Alpha" => 30)); $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0)); /* Write the chart title */ $myPicture->setFontProperties(array("FontName" => "../fonts/Forgotte.ttf", "FontSize" => 11)); $myPicture->drawText(150, 35, "Size by time generations", array("FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => "../fonts/pf_arma_five.ttf", "FontSize" => 6)); /* Define the chart area */ $myPicture->setGraphArea(40, 40, 680, 200); /* Draw the scale */ $scaleSettings = array("LabelSkip" => 4, "XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridAlpha" => 30, "GridR" => 140, "GridG" => 140, "GridB" => 140, "DrawSubTicks" => TRUE); $myPicture->drawScale($scaleSettings); /* Turn on Antialiasing */ $myPicture->Antialias = TRUE; /* Draw the line chart */ $myPicture->drawZoneChart("Bounds 1", "Bounds 2", array("LineAlpha" => 100, "AreaR" => 230, "AreaG" => 230, "AreaB" => 230, "AreaAlpha" => 20, "LineTicks" => 3)); $MyData->setSerieDrawable(array("Bounds 1", "Bounds 2"), FALSE); /* Draw the line chart */ $myPicture->drawLineChart(); $myPicture->drawPlotChart(array("PlotBorder" => TRUE, "PlotSize" => 2, "BorderSize" => 3, "Surrounding" => 60, "BorderAlpha" => 50)); /* Write the chart legend */ $myPicture->drawLegend(640, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */ $myPicture->autoOutput("pictures/example.drawZoneChart.png");
function generate_graph_image($outputfile) { // Create Graph Dataset and set axis attributes $graphData = new pData(); $graphData->setAxisName(0, $this->ytitle_actual); $graphData->addPoints($this->xlabels, "xaxis"); $graphData->setSerieDescription("xaxis", "xaxis"); $graphData->setAbscissa("xaxis"); $graphData->setXAxisName("ooo"); // Add each series of plot values to dataset, but Reportico will // duplicate series were the same data are displayed in different forms // so only add each unique series once $seriesadded = array(); foreach ($this->plot as $k => $v) { $series = $v["name"] . $k; $graphData->addPoints($v["data"], $series); $graphData->setSerieDescription($series, $v["legend"]); } /* $graph->xgrid->SetColor($this->xgridcolor); $graph->ygrid->SetColor($this->ygridcolor); */ /* switch ( $this->xgriddisplay ) { case "all": $graph->xgrid->Show(true,true); break; case "major": $graph->xgrid->Show(true,false); break; case "minor": $graph->xgrid->Show(false,true); break; case "none": default: $graph->xgrid->Show(false,false); break; } switch ( $this->ygriddisplay ) { case "all": $graph->ygrid->Show(true,true); break; case "major": $graph->ygrid->Show(true,false); break; case "minor": $graph->ygrid->Show(false,true); break; case "none": default: $graph->ygrid->Show(false,false); break; } */ /* $graph->xaxis->SetFont($fontfamilies[$xaxisfont],$fontstyles[$xaxisfontstyle], $xaxisfontsize); $graph->xaxis->SetColor($xaxiscolor,$xaxisfontcolor); $graph->yaxis->SetFont($fontfamilies[$yaxisfont],$fontstyles[$yaxisfontstyle], $yaxisfontsize); $graph->yaxis->SetColor($yaxiscolor,$yaxisfontcolor); $graph->xaxis->title->SetFont($fontfamilies[$xtitlefont],$fontstyles[$xtitlefontstyle], $xtitlefontsize); $graph->xaxis->title->SetColor($xtitlecolor); $graph->yaxis->title->SetFont($fontfamilies[$ytitlefont],$fontstyles[$ytitlefontstyle], $ytitlefontsize); $graph->yaxis->title->SetColor($ytitlecolor); $graph->xaxis->SetLabelAngle(90); $graph->xaxis->SetLabelMargin(15); $graph->yaxis->SetLabelMargin(15); $graph->xaxis->SetTickLabels($xlabels); $graph->xaxis->SetTextLabelInterval($xticklabint); $graph->yaxis->SetTextLabelInterval($yticklabint); $graph->xaxis->SetTextTickInterval($xtickinterval); $graph->yaxis->SetTextTickInterval($ytickinterval); */ /* if ( $gridpos == "front" ) $graph->SetGridDepth(DEPTH_FRONT); */ // Display the graph /*?$graph->Stroke();*/ $this->apply_defaults_internal(); //echo "oo<BR>"; //echo "<PRE>"; //var_dump($graphData); //echo $this->width."<BR>"; //echo $this->height_actual."<BR>"; $graphImage = new pImage($this->width_actual, $this->height_actual, $graphData); /* Turn of Antialiasing */ $graphImage->Antialias = TRUE; // Add gradient fill from chosen background color to white $startgradient = $this->htmltorgb("#ffffff"); $color = $this->htmltorgb($this->graphcolor); $graphImage->drawGradientArea(0, 0, $this->width_actual, $this->height_actual, DIRECTION_VERTICAL, array("StartR" => $startgradient[0], "StartG" => $startgradient[1], "StartB" => $startgradient[2], "EndR" => $color[0], "EndG" => $color[1], "EndB" => $color[2], "Alpha" => 100)); /* Add a border to the picture */ $graphImage->drawRectangle(0, 0, $this->width_actual - 1, $this->height_actual - 1, array("R" => 200, "G" => 200, "B" => 200)); /* Set the title font and draw it */ $graphImage->setFontProperties(array("FontName" => PCHARTFONTS_DIR . $this->titlefont, "FontSize" => $this->titlefontsize)); $this->titlecolor = $this->htmltorgb($this->titlecolor); $graphImage->drawText(20, 30, $this->title_actual, array("R" => $this->titlecolor[0], "G" => $this->titlecolor[1], "B" => $this->titlecolor[2])); /* Set the default font from the X title font */ $graphImage->setFontProperties(array("FontName" => PCHARTFONTS_DIR . $this->xtitlefont, "FontSize" => $this->xtitlefontsize)); /* Define the chart area */ $graphImage->setGraphArea($this->marginleft, $this->margintop, $this->width_actual - $this->marginright, $this->height_actual - $this->marginbottom); //$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE,"LabelRotation"=>30); //$graphImage->drawScale($scaleSettings); //$settings = array("Surrounding"=>-30,"InnerSurrounding"=>30); //$graphImage->drawBarChart($settings); //$graphImage->autoOutput("pictures/example.drawBarChart.simple.png"); //return; // Before plotting a series ensure they are all not drawable. /// Plot the chart data $stackeddrawn = false; $stackedexists = false; $barexists = false; foreach ($this->plot as $k => $v) { if ($v["type"] == "STACKEDBAR") { $stackedexists = true; } if ($v["type"] == "STACKEDBAR" || $v["type"] == "BAR") { $barexists = true; } } /* Draw the scale */ $scaleSettings = array("GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE, "LabelRotation" => 30); // For stacked charts fix up the Max and Min values; if ($stackedexists) { $scaleMin = "Unknown"; $scaleMax = 0; foreach ($this->plot as $k => $v) { if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") { $series = $v["name"] . $k; $min = $graphData->getMin($series); if ($scaleMin == "Unknown" || $min < $scaleMin) { $scaleMin = $min; } $scaleMax = $scaleMax + $graphData->getMax($series); } } if ($scaleMin > 0) { $scaleMin = 0; } $range = $scaleMax - $scaleMin; // Make scales based on 5% of the range of values $scaleMax = round($range * 0.05 + $scaleMax); if ($scaleMin < 0) { $scaleMin = $scaleMin - round($range * 0.05); } $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax)); $scaleSettings["Mode"] = SCALE_MODE_MANUAL; $scaleSettings["ManualScale"] = $AxisBoundaries; } else { if ($barexists) { $scaleMin = "Unknown"; $scaleMax = 0; foreach ($this->plot as $k => $v) { if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") { $series = $v["name"] . $k; $min = $graphData->getMin($series); if ($scaleMin == "Unknown" || $min < $scaleMin) { $scaleMin = $min; } $max = $graphData->getMax($series); if ($scaleMax == "Unknown" || $max > $scaleMax) { $scaleMax = $max; } } } if ($scaleMin > 0) { $scaleMin = 0; } $range = $scaleMax - $scaleMin; // Make scales based on 5% of the range of values $scaleMax = round($range * 0.05 + $scaleMax); if ($scaleMin < 0) { $scaleMin = $scaleMin - round($range * 0.05); } $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax)); $scaleSettings["Mode"] = SCALE_MODE_MANUAL; $scaleSettings["ManualScale"] = $AxisBoundaries; } } $graphImage->drawScale($scaleSettings); // If there's a Pie chart we want to draw different legends $piechart = false; foreach ($this->plot as $k => $v) { foreach ($this->plot as $k1 => $v1) { $series = $v1["name"] . $k1; $graphData->setSerieDrawable($series, FALSE); } $series = $v["name"] . $k; $graphData->setSerieDrawable($series, TRUE); switch ($v["type"]) { case "PIE": $piechart = true; $pie = new pPie($graphImage, $graphData); //$pie->draw2DPie($width_actual / 2,$height_actual / 2,80,array("DrawLabels"=>TRUE,"LabelStacked"=>TRUE,"Border"=>TRUE)); $pie->draw2DPie($width_actual / 2, $height_actual / 2, 80, array("WriteValues" => PIE_VALUE_PERCENTAGE, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => TRUE, "BorderR" => 255, "BorderG" => 255, "BorderB" => 255)); break; case "PIE3D": $piechart = true; $pie = new pPie($graphImage, $graphData); $pie->draw3DPie($this->width_actual / 2, $this->height_actual / 2, 80, array("SecondPass" => FALSE)); break; case "STACKEDBAR": case "BAR": if ($stackeddrawn) { break; } if ($barexists) { foreach ($this->plot as $k1 => $v1) { if ($v1["type"] == "BAR" || $v1["type"] == "STACKEDBAR") { $graphData->setSerieDrawable($v1["name"] . $k1, TRUE); } } } $stackeddrawn = true; $settings = array("Surrounding" => -30, "InnerSurrounding" => 30); if ($stackedexists) { $graphImage->drawStackedBarChart($settings); } else { $graphImage->drawBarChart($settings); } break; case "LINE": default: if (count($v["data"]) == 1) { $v["data"][] = 0; } $graphImage->drawLineChart($settings); break; } } $graphData->drawAll(); if ($piechart) { $pie->drawPieLegend($this->width_actual - 100, 30, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL)); } else { $graphImage->drawLegend($this->width_actual - 180, 22, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL)); } $graphImage->setShadow(TRUE, array("X" => 0, "Y" => 0, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); $graphImage->render($outputfile); return true; }
function createGraphe($vData, $hData, $titre, $vLabel, $hLabel) { $MyData = new pData(); /*Je présente ma série de données à utiliser pour le graphique et je détermine le titre de l'axe vertical avec setAxisName*/ $MyData->addPoints($vData, "vertical"); $MyData->setSerieWeight("vertical", 2); $MyData->setAxisName(0, $vLabel); /*J'indique les données horizontales du graphique. Il doit y avoir le même nombre que pour ma série de données précédentes (logique)*/ $MyData->addPoints($hData, "horizontal"); $MyData->setSerieDescription("horizontal", $hLabel); $MyData->setAbscissa("horizontal"); $MyData->setPalette("vertical", array("R" => 255, "G" => 0, "B" => 0)); /* Je crée l'image qui contiendra mon graphique précédemment crée */ $myPicture = new pImage(900, 400, $MyData); /* Je crée une bordure à mon image */ $myPicture->drawRectangle(0, 0, 899, 399, array("R" => 0, "G" => 0, "B" => 0)); /* J'indique le titre de mon graphique, son positionnement sur l'image et sa police */ $myPicture->setFontProperties(array("FontName" => "./pChart2.1.4/fonts/Forgotte.ttf", "FontSize" => 11)); $myPicture->drawText(200, 25, $titre, array("FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); /* Je choisi la font de mon graphique */ $myPicture->setFontProperties(array("FontName" => "./pChart2.1.4/fonts/pf_arma_five.ttf", "FontSize" => 6)); /* Je détermine la taille du graphique et son emplacement dans l'image */ $myPicture->setGraphArea(60, 40, 800, 380); /* Paramètres pour dessiner le graphique à partir des deux abscisses */ $scaleSettings = array("XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => FALSE, "CycleBackground" => TRUE, "LabelSkip" => 4); $myPicture->drawScale($scaleSettings); /* Je dessine mon graphique en fonction des paramètres précédents */ $myPicture->drawAreaChart(); $myPicture->drawLineChart(); /* J'indique le chemin où je souhaite que mon image soit créée */ $myPicture->Render("img/" . $titre . ".png"); }
function pch_vertical_graph($graph_type, $index, $data, $width, $height, $rgb_color = false, $xaxisname = "", $yaxisname = "", $show_values = false, $legend = array(), $font, $antialiasing, $water_mark = '', $font_size) { /* CAT:Vertical Charts */ if (!is_array($legend) || empty($legend)) { unset($legend); } /*$legend=array('pep1' => 'pep1','pep2' => 'pep2','pep3' => 'pep3','pep4' => 'pep4'); $data=array(array('pep1' => 1, 'pep2' => 1, 'pep3' => 3, 'pep4' => 3), array('pep1' => 1, 'pep2' => 3, 'pep3' => 1,'pep4' => 4), array('pep1' => 3, 'pep2' => 1, 'pep3' => 1,'pep4' =>1), array('pep1' => 1, 'pep2' =>1, 'pep3' =>1,'pep4' =>0)); $index=array(1,2,3,4); */ if (is_array(reset($data))) { $data2 = array(); foreach ($data as $i => $values) { $c = 0; foreach ($values as $i2 => $value) { $data2[$i2][$i] = $value; $c++; } } $data = $data2; } else { $data = array($data); } /* Create and populate the pData object */ $MyData = new pData(); foreach ($data as $i => $values) { if (isset($legend)) { $point_id = $legend[$i]; } else { $point_id = $i; } $MyData->addPoints($values, $point_id); if (!empty($rgb_color)) { $MyData->setPalette($point_id, array("R" => $rgb_color[$i]['color']["R"], "G" => $rgb_color[$i]['color']["G"], "B" => $rgb_color[$i]['color']["B"], "BorderR" => $rgb_color[$i]['border']["R"], "BorderG" => $rgb_color[$i]['border']["G"], "BorderB" => $rgb_color[$i]['border']["B"], "Alpha" => $rgb_color[$i]['alpha'])); /*$palette_color = array(); if (isset($rgb_color[$i]['color'])) { $palette_color["R"] = $rgb_color[$i]['color']["R"]; $palette_color["G"] = $rgb_color[$i]['color']["G"]; $palette_color["B"] = $rgb_color[$i]['color']["B"]; } if (isset($rgb_color[$i]['color'])) { $palette_color["BorderR"] = $rgb_color[$i]['border']["R"]; $palette_color["BorderG"] = $rgb_color[$i]['border']["G"]; $palette_color["BorderB"] = $rgb_color[$i]['border']["B"]; } if (isset($rgb_color[$i]['color'])) { $palette_color["Alpha"] = $rgb_color[$i]['Alpha']; } $MyData->setPalette($point_id, $palette_color);*/ } $MyData->setSerieWeight($point_id, 1); } //$MyData->addPoints($data,"Yaxis"); $MyData->setAxisName(0, $yaxisname); $MyData->addPoints($index, "Xaxis"); $MyData->setSerieDescription("Xaxis", $xaxisname); $MyData->setAbscissa("Xaxis"); /* Create the pChart object */ $myPicture = new pImage($width, $height, $MyData); /* Turn of Antialiasing */ $myPicture->Antialias = $antialiasing; /* Add a border to the picture */ //$myPicture->drawRectangle(0,0,$width,$height,array("R"=>0,"G"=>0,"B"=>0)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => $font, "FontSize" => $font_size)); if (isset($legend)) { /* Set horizontal legend if is posible */ $legend_mode = LEGEND_HORIZONTAL; $size = $myPicture->getLegendSize(array("Style" => LEGEND_NOBORDER, "Mode" => $legend_mode)); if ($size['Width'] > $width - 5) { $legend_mode = LEGEND_VERTICAL; $size = $myPicture->getLegendSize(array("Style" => LEGEND_NOBORDER, "Mode" => $legend_mode)); } /* Write the chart legend */ $myPicture->drawLegend($width - $size['Width'], 8, array("Style" => LEGEND_NOBORDER, "Mode" => $legend_mode)); } //Calculate the bottom margin from the size of string in each index $max_chars = 0; foreach ($index as $string_index) { if (empty($string_index)) { continue; } $len = strlen($string_index); if ($len > $max_chars) { $max_chars = $len; } } $margin_bottom = 10 * $max_chars; $water_mark_height = 0; $water_mark_width = 0; if (!empty($water_mark)) { $size_water_mark = getimagesize($water_mark); $water_mark_height = $size_water_mark[1]; $water_mark_width = $size_water_mark[0]; $myPicture->drawFromPNG($width - $water_mark_width, $height - $water_mark_height - $margin_bottom, $water_mark); } if (isset($size['Height'])) { /* Define the chart area */ $myPicture->setGraphArea(40, $size['Height'], $width - $water_mark_width, $height - $margin_bottom); } else { /* Define the chart area */ $myPicture->setGraphArea(40, 5, $width - $water_mark_width, $height - $margin_bottom); } /* Draw the scale */ $scaleSettings = array("GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE, "Mode" => SCALE_MODE_START0, "LabelRotation" => 60, "XMargin" => 0); $myPicture->drawScale($scaleSettings); /* Turn on shadow computing */ //$myPicture->setShadow(TRUE,array("X"=>0,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); switch ($graph_type) { case 'stacked_area': $ForceTransparency = "-1"; break; default: $ForceTransparency = "50"; break; } /* Draw the chart */ $settings = array("ForceTransparency" => $ForceTransparency, "Gradient" => TRUE, "GradientMode" => GRADIENT_EFFECT_CAN, "DisplayValues" => $show_values, "DisplayZeroValues" => FALSE, "DisplayR" => 100, "DisplayZeros" => FALSE, "DisplayG" => 100, "DisplayB" => 100, "DisplayShadow" => TRUE, "Surrounding" => 5, "AroundZero" => FALSE); switch ($graph_type) { case "stacked_area": case "area": $myPicture->drawAreaChart($settings); break; case "line": $myPicture->drawLineChart($settings); break; } /* Render the picture */ $myPicture->stroke(); }
private function drawOverAllImage($date) { $res1 = $this->dataForGraph($date, 0); $res2 = $this->dataForGraph($date, 1); $MyData = new pData(); $MyData->addPoints($res1['percents'], "Load in % for server 1"); $MyData->addPoints($res2['percents'], "Load in % for server 2"); $MyData->setAxisName(0, "Participants"); $MyData->addPoints($res1['times'], "Labels"); // $MyData->addPoints($res2['times'], "Labels"); $MyData->setSerieDescription("Labels", "Months"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(1200, 560, $MyData); /* Turn of Antialiasing */ $myPicture->Antialias = TRUE; /* Add a border to the picture */ //$myPicture->drawRectangle(0,0,890,290,array("R"=>0,"G"=>0,"B"=>0)); /* Write the chart title */ $myPicture->setFontProperties(array("FontName" => CORE_REPOSITORY_REAL_PATH . "class/pChart/fonts/Forgotte.ttf", "FontSize" => 11)); $myPicture->drawText(200, 35, "All Servers Resource Usage (" . $date . ")", array("FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => CORE_REPOSITORY_REAL_PATH . "class/pChart/fonts/pf_arma_five.ttf", "FontSize" => 8)); /* Define the chart area */ $myPicture->setGraphArea(60, 40, 1100, 500); $AxisBoundaries = array(0 => array("Min" => 0, "Max" => 100)); /* Draw the scale */ $scaleSettings = array("XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE, "LabelSkip" => 1, 'Mode' => SCALE_MODE_MANUAL, "ManualScale" => $AxisBoundaries); $myPicture->drawScale($scaleSettings); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); /* Draw the stacked area chart */ $myPicture->drawStackedAreaChart(array("DrawLine" => TRUE, "LineSurrounding" => -20)); /* Turn on Antialiasing */ $myPicture->Antialias = TRUE; /* Draw the line chart */ $myPicture->drawLineChart(); /* Write the chart legend */ $myPicture->drawLegend(800, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */ //$myPicture->autoOutput(App::$instance->opt->fizPath."class/pChart/pictures/example.drawLineChart.simple.png"); $myPicture->render(CORE_REPOSITORY_REAL_PATH . "class/pChart/pictures/load_at_" . $date . "_on_overall.png"); $path = CORE_REPOSITORY_HTTP_PATH . "class/pChart/pictures/load_at_" . $date . "_on_overall.png"; if (ST::isAjaxRequest()) { $data = []; print json_encode($data['path'] = $path); } else { return $path; } }
$Test->drawAreaChart(array("AroundZero" => FALSE)); // заполнение снизу до кривой графика // $Test->drawAreaChart(array("AroundZero"=>TRUE)); // заполнение от нуля до кривой графика } elseif ($_GET['gtype'] == 'bar') { //рисуем столбы //$Test->drawFilledRectangle(60,60,450,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10)); //$Test->drawScale(array("DrawSubTicks"=>TRUE)); $Test->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); //$Test->setFontProperties(array("FontName"=>"../fonts/pf_arma_five.ttf","FontSize"=>6)); $Test->drawBarChart(array("DisplayValues" => FALSE, "Interleave" => 0.2, "Gradient" => TRUE, "DisplayColor" => DISPLAY_AUTO, "Rounded" => FALSE, "AroundZero" => TRUE, "Surrounding" => 0)); } else { //рисуем прямолинейный график //$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); //$Test->clearShadow(); //$Test->drawFilledLineGraph($DataSet->GetData(),$DataSet->GetDataDescription(), 30); $Test->drawLineChart(array("DisplayValues" => FALSE, "BreakVoid" => FALSE, "VoidTicks" => 0, "DisplayColor" => DISPLAY_AUTO)); //$Test->drawAreaChart(array("AroundZero"=>FALSE)); // заполнение снизу до кривой графика $Test->drawAreaChart(array("AroundZero" => TRUE)); // заполнение от нуля до кривой графика } /* Render the picture (choose the best way) */ $path_to_file = './cached/' . md5($_SERVER['REQUEST_URI']) . '.png'; imagepng($Test->autoOutput($path_to_file)); Header("Content-type:image/png"); $fsize = filesize($path_to_file); header("Content-Length:" . (string) $fsize); $buff_length = 200 * 1024; if ($buff_length > $fsize) { $buff_length = $fsize; } if ($buff_length > 0) {
} } $stackeddrawn = true; $settings = array("Surrounding" => -30, "InnerSurrounding" => 30); if ($stackedexists) { $graphImage->drawStackedBarChart($settings); } else { $graphImage->drawBarChart($settings); } break; case "LINE": default: if (count($v["data"]) == 1) { $v["data"][] = 0; } $graphImage->drawLineChart($settings); break; } } $graphData->drawAll(); if ($piechart) { $pie->drawPieLegend($width - 100, 30, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL)); } else { $graphImage->drawLegend($width - 180, 22, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL)); } $graphImage->setShadow(TRUE, array("X" => 0, "Y" => 0, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); $graphImage->autoOutput("pictures/example.drawBarChart.simple.png"); function htmltorgb($color) { if ($color[0] == '#') { $color = substr($color, 1);
static function makeChartArticle($type, $data, $events, $colors, $lang = "en") { global $wt, $I18N; $font = PCHART_FONTS_PATH . "/LiberationSans-Regular.ttf"; if (in_array($wt->uselang, array("zh", "ja", "jp", "ko"))) { $font = PCHART_FONTS_PATH . "/wqy-microhei.ttf"; } if (in_array($wt->uselang, array("he", "bn", "vi", "fa", "ar", "th", "ta", "ka", "hi", "hy", "ml"))) { $font = PCHART_FONTS_PATH . "/unifont.ttf"; } $maxsizeTotal = 0; $maxeditTotal = 0; $u = 0; foreach ($data as $year => $values) { $years[] = $year; $all[] = $values["all"]; $minor[] = $values["minor"]; $anon[] = $values["anon"]; $maxsize = 0; //get the max size of each month foreach ($values["months"] as $i => $mdetails) { if ($mdetails["size"] > $maxsize) { $maxsize = $mdetails["size"]; } } $tmpssize[] = $maxsize ? $maxsize : $tmpssize[$u - 1]; $linemarker[] = 1; $eventmarker[] = isset($events[$year]["protect"]) ? 10 + $events[$year]["protect"] * 3 : 0; $u++; } $msgAll = $I18N->msg('all'); $msgMinor = $I18N->msg('minor'); $msgPagesize = $I18N->msg('pagesize'); $MyData = new pData(); $MyData->addPoints($all, "all"); $MyData->addPoints($minor, "minor"); $MyData->addPoints($anon, "anon"); $MyData->addPoints($tmpssize, "size"); $MyData->addPoints($eventmarker, "protect"); $MyData->setSerieOnAxis("all", 0); $MyData->setSerieOnAxis("minor", 0); $MyData->setSerieOnAxis("anon", 0); $MyData->setSerieOnAxis("size", 1); $MyData->setSerieOnAxis("protect", 1); $MyData->setAxisPosition(1, AXIS_POSITION_RIGHT); $MyData->setAxisName(0, "Edits"); $MyData->setAxisName(1, "Size (kb)"); $MyData->Data["Series"]["all"]["Color"] = self::hex2rgb($colors["all"], 200, true); $MyData->Data["Series"]["minor"]["Color"] = self::hex2rgb($colors["minor"], 200, true); $MyData->Data["Series"]["anon"]["Color"] = self::hex2rgb($colors["anon"], 200, true); $MyData->Data["Series"]["size"]["Color"] = self::hex2rgb($colors["size"], 200, true); $MyData->Data["Series"]["protect"]["Color"] = self::hex2rgb($colors["protect"], 200, true); $MyData->addPoints($years, "Labels"); $MyData->setAbscissa("Labels"); $myPicture = new pImage(1000, 300, $MyData, TRUE); $myPicture->setFontProperties(array("FontName" => $font, "FontSize" => 12, "R" => 34, "G" => 34, "B" => 34)); $myPicture->setGraphArea(50, 30, 820, 270); $myPicture->setFontProperties(array("FontName" => $font, "FontSize" => 8)); $scaleSettings = array("AxisR" => 134, "AxisG" => 134, "AxisB" => 134, "AxisAplha" => 40, "DrawSubTicks" => TRUE, "CycleBackground" => false, "LabelRotation" => 0, "LabelSkip" => 0, "Mode" => SCALE_MODE_START0); $myPicture->drawScale($scaleSettings); $settings = array("Surrounding" => -30, "InnerSurrounding" => 10, "RecordImageMap" => false, "DisplayValues" => false); $MyData->setSerieDrawable('size', false); $MyData->setSerieDrawable('protect', false); $myPicture->drawBarChart($settings); $MyData->setSerieDrawable('size', true); $MyData->setSerieDrawable('all', false); $MyData->setSerieDrawable('minor', false); $MyData->setSerieDrawable('anon', false); $MyData->setSerieDrawable('protect', false); $myPicture->drawLineChart(); $MyData->setSerieDrawable('protect', true); $MyData->setSerieDrawable('size', true); $myBubbleChart = new pBubble($myPicture, $MyData); $bubbleDataSeries = array("size"); $bubbleWeightSeries = array("protect"); $myBubbleChart->bubbleScale($bubbleDataSeries, $bubbleWeightSeries); $myBubbleChart->drawBubbleChart($bubbleDataSeries, $bubbleWeightSeries, array("ForceAlpha" => true)); $myPicture->setFontProperties(array("FontName" => $font, "FontSize" => 11, "R" => 34, "G" => 34, "B" => 34)); $MyData->setSerieDrawable('size', true); $MyData->setSerieDrawable('all', true); $MyData->setSerieDrawable('minor', true); $MyData->setSerieDrawable('anon', true); $MyData->setSerieDrawable('protect', true); $myPicture->drawLegend(900, 55, array("Style" => LEGEND_NOBORDER, "BoxWidth" => 10, "BoxHeight" => 10, "Mode" => LEGEND_VERTICAL)); ob_start(); imagepng($myPicture->Picture); $imgdata = ob_get_contents(); ob_end_clean(); $rimg = "data:image/png;base64," . base64_encode($imgdata); return $rimg; }
$DataSet->addPoints(array(7.5, 8, 7.5, 10, 6, 6), "Pedro"); // Pedro $DataSet->setAxisName(0, 'Horas'); // unidade $DataSet->setAxisUnit(0, 'h'); // Labels $DataSet->addPoints(array('Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'), 'Dias'); $DataSet->setSerieDescription('Dias', 'Dias da Semana'); $DataSet->setAbscissa('Dias'); // Inicializando o gráfico - Largura e Altura $Graph = new pImage(700, 230, $DataSet); // Fonte padrão para os textos $Graph->setFontProperties(array('FontName' => "pChart/fonts/verdana.ttf", 'FontSize' => 8)); // Área utilizada para plotar o gráfico - x1, y1, x2, y2 $Graph->setGraphArea(50, 40, 670, 190); // RGB, Subticks no eixo, Fundo cores alternadas // ver: http://wiki.pchart.net/doc.doc.draw.scale.html $scale = array('GridR' => 150, 'GridG' => 150, 'GridB' => 150, 'DrawSubTicks' => true, 'CycleBackground' => true); $Graph->drawScale($scale); $Graph->drawLineChart(); // Finaliza o gráfico // colocando a legenda dos valores $Graph->drawLegend(540, 25, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); // Fonte do título $Graph->setFontProperties(array('FontName' => "pChart/fonts/verdana.ttf", 'FontSize' => 10)); // título $Graph->drawText(60, 20, "Horas Trabalhadas"); // Cria a imagem e salva em arquivo //$Graph->autoOutput('/tmp/teste.png'); // Cria a imagem e devolve para o browser $Graph->autoOutput();
$myPicture->initialiseImageMap("ImageMapLineChart", IMAGE_MAP_STORAGE_FILE, "LineChart", "../tmp"); /* Turn of Antialiasing */ $myPicture->Antialias = FALSE; /* Draw the background */ $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107); $myPicture->drawFilledRectangle(0, 0, 700, 230, $Settings); /* Overlay with a gradient */ $Settings = array("StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $Settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0)); /* Write the chart title */ $myPicture->setFontProperties(array("FontName" => FONT_PATH . "/Forgotte.ttf", "FontSize" => 11)); $myPicture->drawText(150, 35, "Average temperature", array("FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => FONT_PATH . "/pf_arma_five.ttf", "FontSize" => 6)); /* Define the chart area */ $myPicture->setGraphArea(60, 40, 650, 200); /* Draw the scale */ $scaleSettings = array("XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE); $myPicture->drawScale($scaleSettings); /* Turn on Antialiasing */ $myPicture->Antialias = TRUE; /* Draw the line chart */ $Settings = array("RecordImageMap" => TRUE); $myPicture->drawLineChart($Settings); $myPicture->drawPlotChart(array("PlotBorder" => TRUE, "BorderSize" => 1, "Surrounding" => -60, "BorderAlpha" => 80)); /* Write the chart legend */ $myPicture->drawLegend(540, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */ $myPicture->autoOutput("../tmp/LineChart.png");
function generateGraphByStatus($periodData, $periods, $statuses) { global $configArray; global $interface; $reportData = new pData(); //Add points for each status $periodsFormatted = array(); foreach ($statuses as $status => $statusLabel) { $statusData = array(); foreach ($periodData as $date => $periodInfo) { $periodsFormatted[$date] = date('M-d-Y', $date); $statusData[$date] = isset($periodInfo[$status]) ? $periodInfo[$status] : 0; } $reportData->addPoints($statusData, $status); } $reportData->setAxisName(0, "Number of files"); $reportData->addPoints($periodsFormatted, "Dates"); $reportData->setAbscissa("Dates"); /* Create the pChart object */ $myPicture = new pImage(700, 290, $reportData); /* Draw the background */ $Settings = array("R" => 225, "G" => 225, "B" => 225); $myPicture->drawFilledRectangle(0, 0, 700, 290, $Settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 699, 289, array("R" => 0, "G" => 0, "B" => 0)); $myPicture->setFontProperties(array("FontName" => "sys/pChart/Fonts/verdana.ttf", "FontSize" => 9)); $myPicture->setGraphArea(50, 30, 670, 190); //$myPicture->drawFilledRectangle(30,30,670,150,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10)); $myPicture->drawScale(array("DrawSubTicks" => TRUE, "LabelRotation" => 90)); $myPicture->setFontProperties(array("FontName" => "sys/pChart/Fonts/verdana.ttf", "FontSize" => 9)); $myPicture->drawLineChart(array("DisplayValues" => TRUE, "DisplayColor" => DISPLAY_AUTO)); /* Write the chart legend */ $myPicture->drawLegend(80, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */ $chartHref = "/images/charts/eContentImportSummaryByStatus" . time() . ".png"; $chartPath = $configArray['Site']['local'] . $chartHref; $myPicture->render($chartPath); $interface->assign('chartByStatus', $chartHref); }
$latest = $MyData->Data['Series']['Pressure']['Data'][0]; /* Reverse series so latest value is on the right */ $MyData->reverseSerie("Temperature"); $MyData->reverseSerie("CPU-Temp"); $MyData->reverseSerie("Pressure"); $earliest = $MyData->Data['Series']['Pressure']['Data'][0]; /* Create the chart*/ $myPicture = new pImage(800, 500, $MyData); $myPicture->setFontProperties(array("FontName" => "/var/www/html/pChart/fonts/Forgotte.ttf", "FontSize" => 10)); $myPicture->setGraphArea(90, 60, 750, 450); /* Title of Chart */ $myPicture->drawText(395, 55, "BAROMETER", array("FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); $myPicture->drawText(163, 55, "Earliest Pressure :", array("FontSize" => 16, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); $myPicture->drawText(255, 55, $earliest, array("FontSize" => 16, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); $myPicture->drawText(637, 55, "Latest Pressure :", array("FontSize" => 16, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); $myPicture->drawText(718, 55, $latest, array("FontSize" => 16, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); $latest = $MyData->Data['Series']['Pressure']['Data'][1]; $myPicture->drawFilledRectangle(90, 60, 750, 450, array("R" => 0, "G" => 155, "B" => 155, "Surrounding" => -200, "Alpha" => 10)); $AxisBoundaries = array(0 => array("Min" => 0, "Max" => 70), 1 => array("Min" => 0, "Max" => 70), 2 => array("Min" => 980, "Max" => 1020)); $ScaleSettings = array("Mode" => SCALE_MODE_MANUAL, "ManualScale" => $AxisBoundaries, "DrawSubTicks" => TRUE, "DrawArrows" => TRUE, "ArrowSize" => 6, "CycleBackground" => TRUE, "GridR" => 102, "GridG" => 102, "GridB" => 102, "DrawXLines" => TRUE, "DrawYLines" => array(2), "LabelSkip" => 11); $myPicture->drawScale($ScaleSettings); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); $myPicture->drawLineChart(array("DisplayValues" => FALSE, "DisplayColor" => DISPLAY_AUTO)); //$myPicture->setShadow(FALSE); /* Write the chart legend */ $myPicture->drawLegend(550, 430, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); $myPicture->autoOutput("/var/ram/chart.png"); //$myPicture->Render("/var/ram/chart.png"); //$myPicture->Stroke("/var/ram/chart.png"); /* header('Content-type: image/png'); */ echo '<img src="file://localhost/var/ram/chart.png" width=700 height=100 />';
function PlotLine($rowX, $rowY, $name, $ch) { include $_SERVER['DOCUMENT_ROOT'] . "/TBSIM/Lib/class/pData.class.php"; include $_SERVER['DOCUMENT_ROOT'] . "/TBSIM/Lib/class/pDraw.class.php"; include $_SERVER['DOCUMENT_ROOT'] . "/TBSIM/Lib/class/pImage.class.php"; include $_SERVER['DOCUMENT_ROOT'] . "/TBSIM/Lib/class/pPie.class.php"; //************************************** $myData = new pData(); $myData->addPoints($rowX, "Serie1"); $myData->setSerieDescription("Serie1", $name); //$myData->setSerieOnAxis("Serie1",0); $myData->addPoints($rowY, "Absissa"); $myData->setAbscissa("Absissa"); //$myData->addPoints(array("January","February","March","April","May","June","July","August"),"Absissa"); //$myData->setAbscissa("Absissa"); $myData->setAxisPosition(0, AXIS_POSITION_LEFT); //$myData->setAxisName(0,"1st axis"); $myData->setAxisUnit(0, ""); $myPicture = new pImage(700, 230, $myData); $Settings = array("R" => 240, "G" => 242, "B" => 241, "Dash" => 1, "DashR" => 260, "DashG" => 262, "DashB" => 261); $myPicture->drawFilledRectangle(0, 0, 700, 230, $Settings); $Settings = array("StartR" => 252, "StartG" => 255, "StartB" => 254, "EndR" => 252, "EndG" => 255, "EndB" => 254, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $Settings); $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0)); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 20)); $myPicture->setFontProperties(array("FontName" => "fonts/Forgotte.ttf", "FontSize" => 14)); $TextSettings = array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 252, "G" => 252, "B" => 252, "DrawBox" => 1, "BoxAlpha" => 30); //$myPicture->drawText(350,25,$name,$TextSettings); $myPicture->setShadow(FALSE); $myPicture->setGraphArea(50, 50, 675, 190); //$myPicture->setFontProperties(array("R"=>0,"G"=>0,"B"=>0,"FontName"=>"fonts/pf_arma_five.ttf","FontSize"=>6)); $Settings = array("Pos" => SCALE_POS_LEFTRIGHT, "Mode" => SCALE_MODE_FLOATING, "LabelingMethod" => LABELING_ALL, "GridR" => 255, "GridG" => 255, "GridB" => 255, "GridAlpha" => 50, "TickR" => 0, "TickG" => 0, "TickB" => 0, "TickAlpha" => 50, "LabelRotation" => 0, "CycleBackground" => 1, "DrawXLines" => 1, "DrawSubTicks" => 1, "SubTickR" => 255, "SubTickG" => 0, "SubTickB" => 0, "SubTickAlpha" => 50, "DrawYLines" => ALL); $myPicture->drawScale($Settings); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 10)); $Config = ""; if ($ch == 1) { $myPicture->drawSplineChart($Config); } if ($ch == 2) { $myPicture->drawBarChart($Config); } if ($ch == 3) { $myPicture->drawLineChart($Config); } if ($ch == 4) { $myPicture->drawPlotChart($Config); } if ($ch == 5) { $myPicture->drawStepChart($Config); } if ($ch == 6) { $myPicture->drawAreaChart($Config); } if ($ch == 7) { $myPicture->drawFilledSplineChart($Config); } if ($ch == 8) { $myPicture->drawFilledStepChart($Config); } if ($ch == 9) { $myPicture->drawStackedAreaChart($Config); } $Config = array("FontR" => 0, "FontG" => 0, "FontB" => 0, "FontName" => "fonts/pf_arma_five.ttf", "FontSize" => 6, "Margin" => 6, "Alpha" => 30, "BoxSize" => 5, "Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL); $myPicture->drawLegend(563, 16, $Config); $myPicture->stroke(); }
function launch() { global $configArray; global $interface; //////////Populate the Date Filter Start //Grab the Selected Date Start if (isset($_REQUEST['dateFilterStart'])) { if (preg_match('/\\d{1,2}\\/\\d{1,2}\\/\\d{4}/', $_REQUEST['dateFilterStart'])) { $selectedDateStart = DateTime::createFromFormat('m/d/Y', $_REQUEST['dateFilterStart']); $selectedDateStart = $selectedDateStart->getTimestamp(); } else { $selectedDateStart = strtotime($_REQUEST['dateFilterStart']); } } else { $selectedDateStart = strtotime('-30 days'); } $selectedDateStart = date('Y-m-d', $selectedDateStart); $interface->assign('selectedDateStart', $selectedDateStart); //Populate the Date Filter End //Grab the Selected End Date if (isset($_REQUEST['dateFilterEnd'])) { if (preg_match('/\\d{1,2}\\/\\d{1,2}\\/\\d{4}/', $_REQUEST['dateFilterEnd'])) { $selectedDateEnd = DateTime::createFromFormat('m/d/Y', $_REQUEST['dateFilterEnd']); $selectedDateEnd = $selectedDateEnd->getTimestamp(); } else { $selectedDateEnd = strtotime($_REQUEST['dateFilterEnd']); } } else { $selectedDateEnd = strtotime('today'); } $selectedDateEnd = date('Y-m-d', $selectedDateEnd); $interface->assign('selectedDateEnd', $selectedDateEnd); //////////Populate the Stores Filter $queryHostsFilter = "SELECT DISTINCT linkHost AS linkHost FROM external_link_tracking ORDER BY linkHost ASC"; $externalLinkTracking = new ExternalLinkTracking(); $externalLinkTracking->query($queryHostsFilter); $allHosts = array(); while ($externalLinkTracking->fetch()) { $allHosts[] = $externalLinkTracking->linkHost; } $interface->assign('hostFilter', $allHosts); //////////Grab the Selected Hosts Filter Value if (isset($_REQUEST['hostFilter'])) { $selectedHosts = $_REQUEST['hostFilter']; } else { $selectedHosts = $allHosts; } $interface->assign('selectedHosts', $selectedHosts); $baseQueryLinks = "SELECT COUNT(externalLinkId) AS timesFollowed, recordId, linkUrl, linkHost " . "FROM external_link_tracking " . "WHERE (DATE_FORMAT(trackingDate, '%Y-%m-%d')) BETWEEN '" . $selectedDateStart . "' AND '" . $selectedDateEnd . "' "; if (count($selectedHosts) > 0) { $hosts = join("','", $selectedHosts); $baseQueryLinks .= "AND linkHost IN ('" . $hosts . "') "; } $baseQueryLinks .= "GROUP BY recordId, linkUrl "; //////////Get a count of the page view data $queryPurchasesCount = "SELECT COUNT(*) AS RowCount from ( " . $baseQueryLinks . ") As ResultCount"; $resPurchasesCount = mysql_query($queryPurchasesCount); if ($resPurchasesCount > 0) { $rowCount = mysql_fetch_object($resPurchasesCount); $totalResultCount = $rowCount->RowCount; } else { $totalResultCount = 0; } //////////Create the items per page array $itemsPerPageList = $this->getItemsPerPageList(); ///////////////////PAGING $currentPage = 1; $resultTotal = $totalResultCount; $startRecord = 1; if (isset($_GET['itemsPerPage'])) { switch ($_GET['itemsPerPage']) { case "20": $itemsPerPage = 20; $itemsPerPageList["20"]["selected"] = true; break; case "100": $itemsPerPage = 100; $itemsPerPageList["100"]["selected"] = true; break; default: $itemsPerPage = 50; $itemsPerPageList["50"]["selected"] = true; } } else { $itemsPerPage = 50; $itemsPerPageList["50"]["selected"] = true; } $endRecord = $itemsPerPage; $interface->assign('itemsPerPageList', $itemsPerPageList); if (isset($_GET['page'])) { $currentPage = $_GET['page']; // 1st record is easy, work out the start of this page $startRecord = ($currentPage - 1) * $itemsPerPage + 1; // Last record needs more care if ($resultTotal < $itemsPerPage) { // There are less records returned then one page, use total results $endRecord = $resultTotal; } else { if ($currentPage * $itemsPerPage > $resultTotal) { // The end of the current page runs past the last record, use total results $endRecord = $resultTotal; } else { // Otherwise use the last record on this page $endRecord = $currentPage * $itemsPerPage; } } } //////////Get the Page View Data with paging and sorting if (isset($_GET['reportSort'])) { $sortValue = $_GET['reportSort']; } //Create values for how to sort the table. $sortList = $this->getSortList(); if (!isset($sortValue)) { $sortValue = 'UrlASC'; } $sortList[$sortValue]["selected"] = true; $baseQueryLinks .= $sortList[$sortValue]['sql']; //append on a limit to return a result if (!isset($_REQUEST['exportToExcel'])) { $baseQueryLinks .= "LIMIT " . ($startRecord - 1) . ", " . $itemsPerPage . " "; } $resPurchases = mysql_query($baseQueryLinks); $resultsPurchases = array(); if ($resPurchases > 0) { //Build an array based on the data to dump out to the grid $i = 0; while ($r = mysql_fetch_array($resPurchases)) { $recordId = $r['recordId']; $fullId = $r['recordId']; if (preg_match('/econtentRecord(\\d+)/', $recordId, $matches)) { require_once ROOT_DIR . '/sys/eContent/EContentRecord.php'; $econtentRecord = new EContentRecord(); $econtentRecord->id = $matches[1]; $econtentRecord->find(true); $recordId = $econtentRecord->ilsId; $title = $econtentRecord->title; } else { $resource = new Resource(); $resource->record_id = $recordId; $resource->source = 'VuFind'; $resource->find(true); $title = $resource->title; } $tmp = array('recordId' => $recordId, 'recordUrl' => '/Record/' . $fullId, 'title' => $title, 'timesFollowed' => $r['timesFollowed'], 'linkHost' => $r['linkHost'], 'linkUrl' => $r['linkUrl']); $resultsPurchases[$i++] = $tmp; } } $interface->assign('resultLinks', $resultsPurchases); //////////Paging Array $summary = array('page' => $currentPage, 'perPage' => $itemsPerPage, 'resultTotal' => $totalResultCount, 'startRecord' => $startRecord, 'endRecord' => $endRecord); $interface->assign('recordCount', $summary['resultTotal']); $interface->assign('recordStart', $summary['startRecord']); $interface->assign('recordEnd', $summary['endRecord']); // Process Paging using VuFind Pager object if (strrpos($_SERVER["REQUEST_URI"], "page=")) { //replace the page variable with a new one $link = str_replace("page=" . $currentPage, "page=%d", $_SERVER["REQUEST_URI"]); } else { if (strrpos($_SERVER["REQUEST_URI"], "?")) { $link = $_SERVER["REQUEST_URI"] . "&page=%d"; } else { $link = $_SERVER["REQUEST_URI"] . "?page=%d"; } } $options = array('totalItems' => $summary['resultTotal'], 'fileName' => $link, 'perPage' => $summary['perPage']); $pager = new VuFindPager($options); $interface->assign('pageLinks', $pager->getLinks()); ///////////////////END PAGING //////////Sorting $sortUrl = $_SERVER["REQUEST_URI"]; if (isset($sortValue)) { //Set the URL for sorting if (strrpos($_SERVER["REQUEST_URI"], "reportSort=")) { //replace the page variable with a new one $sortUrl = str_replace("sort=" . $currentPage, "reportSort=" . $sortValue, $_SERVER["REQUEST_URI"]); } else { if (strrpos($_SERVER["REQUEST_URI"], "?")) { $sortUrl = $_SERVER["REQUEST_URI"] . "&reportSort=" . $sortValue; } else { $sortUrl = $_SERVER["REQUEST_URI"] . "?reportSort=" . $sortValue; } } } $interface->assign('sortUrl', $sortUrl); $interface->assign('sortList', $sortList); //////////CHART //Create the chart and load data into the results. $queryDailyPurchases = "SELECT DATE_FORMAT(trackingDate, '%Y-%m-%d') as date, COUNT(externalLinkId) AS timesFollowed, linkHost FROM external_link_tracking " . "WHERE (DATE_FORMAT(trackingDate, '%Y-%m-%d')) BETWEEN '" . $selectedDateStart . "' AND '" . $selectedDateEnd . "' "; if (count($selectedHosts) > 0) { $hosts = join("','", $selectedHosts); $queryDailyPurchases .= "AND linkHost IN ('" . $hosts . "') "; } $queryDailyPurchases .= "GROUP BY DATE_FORMAT(trackingDate, '%Y-%m-%d'), linkHost ORDER BY trackingDate ASC"; $dailyUsage = mysql_query($queryDailyPurchases); //Initialize data by loading all of the dates that we are looking at so we can show the correct counts or each series on the right day. $check_date = $selectedDateStart; $datesInReport = array(); $linkUsageByHostByDay = array(); foreach ($allHosts as $hostName) { $linkUsageByHostByDay[$hostName] = array(); } while ($check_date != $selectedDateEnd) { $check_date = date("Y-m-d", strtotime("+1 day", strtotime($check_date))); $datesInReport[] = $check_date; //Default number of link usage for the day to 0 foreach ($allHosts as $host) { $linkUsageByHostByDay[$host][$check_date] = 0; } } //Chart section $reportData = new pData(); while ($r = mysql_fetch_array($dailyUsage)) { $linkHost = $r['linkHost']; $linkUsageByHostByDay[$linkHost][$r['date']] = $r['timesFollowed']; } foreach ($linkUsageByHostByDay as $hostName => $dailyResults) { $reportData->addPoints($dailyResults, $hostName); } $reportData->setAxisName(0, "Usage"); $reportData->addPoints($datesInReport, "Dates"); $reportData->setAbscissa("Dates"); /* Create the pChart object */ $myPicture = new pImage(700, 290, $reportData); /* Draw the background */ $Settings = array("R" => 225, "G" => 225, "B" => 225); $myPicture->drawFilledRectangle(0, 0, 700, 290, $Settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 699, 289, array("R" => 0, "G" => 0, "B" => 0)); $myPicture->setFontProperties(array("FontName" => "sys/pChart/Fonts/verdana.ttf", "FontSize" => 9)); $myPicture->setGraphArea(50, 30, 670, 190); //$myPicture->drawFilledRectangle(30,30,670,150,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10)); $myPicture->drawScale(array("DrawSubTicks" => TRUE, "LabelRotation" => 90)); $myPicture->setFontProperties(array("FontName" => "sys/pChart/Fonts/verdana.ttf", "FontSize" => 9)); $myPicture->drawLineChart(array("DisplayValues" => TRUE, "DisplayColor" => DISPLAY_AUTO)); /* Write the chart legend */ $myPicture->drawLegend(80, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */ $time = time(); $chartHref = "/images/charts/dailyPurchases{$time}.png"; $chartPath = $configArray['Site']['local'] . $chartHref; $myPicture->render($chartPath); $interface->assign('chartPath', $chartHref); //////////EXPORT To EXCEL if (isset($_REQUEST['exportToExcel'])) { //PHPEXCEL // Create new PHPExcel object $objPHPExcel = new PHPExcel(); // Set properties $objPHPExcel->getProperties()->setTitle("External Link Usage Report")->setCategory("External Link Usage Report"); // Add some data $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'External Link Usage Report')->setCellValue('A3', 'Record Id')->setCellValue('B3', 'Url')->setCellValue('C3', 'Host')->setCellValue('D3', 'Usage'); $a = 4; //Loop Through The Report Data foreach ($resultsPurchases as $resultsPurchase) { $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $a, $resultsPurchase['recordId'])->setCellValue('B' . $a, $resultsPurchase['linkUrl'])->setCellValue('C' . $a, $resultsPurchase['linkHost'])->setCellValue('D' . $a, $resultsPurchase['timesFollowed']); $a++; } $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true); // Rename sheet $objPHPExcel->getActiveSheet()->setTitle('Simple'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Redirect output to a client's web browser (Excel5) header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="ExternalLinkReport.xls"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; } $interface->setPageTitle('Report - External Link Tracking'); $interface->setTemplate('reportExternalLinks.tpl'); $interface->display('layout.tpl'); }
/* Draw the scale */ $scaleSettings = array("XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 200, "GridAlpha" => 100, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE); $myPicture->drawScale($scaleSettings); /* Write the chart legend */ //$myPicture->drawLegend(640,20,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); /* Turn on Antialiasing */ $myPicture->Antialias = TRUE; /* Enable shadow computing */ //$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); /* Draw the area chart */ //$Threshold = ""; // $Threshold[] = array("Min"=>0,"Max"=>5,"R"=>187,"G"=>220,"B"=>0,"Alpha"=>100); //$Threshold[] = array("Min"=>5,"Max"=>10,"R"=>240,"G"=>132,"B"=>20,"Alpha"=>100); // $Threshold[] = array("Min"=>10,"Max"=>20,"R"=>240,"G"=>91,"B"=>20,"Alpha"=>100); //$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>20)); //$myPicture->drawAreaChart(array("Threshold"=>$Threshold)); /* Draw a line chart over */ $myPicture->drawLineChart(array("ForceColor" => TRUE, "ForceR" => 0, "ForceG" => 0, "ForceB" => 0)); /* Draw a plot chart over */ //$myPicture->drawPlotChart(array("PlotBorder"=>TRUE,"BorderSize"=>1,"Surrounding"=>-255,"BorderAlpha"=>80)); /* Write the thresholds */ $myPicture->drawThreshold(3000, array("WriteCaption" => FALSE, "Caption" => "tiefentladen", "Alpha" => 70, "Ticks" => 2, "R" => 0, "G" => 0, "B" => 255)); $myPicture->drawThreshold(4250, array("WriteCaption" => FALSE, "Caption" => "tiefentladen", "Alpha" => 70, "Ticks" => 2, "R" => 0, "G" => 0, "B" => 255)); //$myPicture->drawThreshold(10,array("WriteCaption"=>TRUE,"Caption"=>"Error Zone","Alpha"=>70,"Ticks"=>2,"R"=>0,"G"=>0,"B"=>255)); /* Render the picture (choose the best way) */ //imagejpeg ( $myPicture, "myPicture.jpg" , 100); //saves Image to Server $myPicture->render("voltage.png"); // debug ==> picture debug... show image // header('Content-Type: image/png'); // imagejpeg ( $myPicture); //$myPicture->autoOutput("pictures/example.drawAreaChart.threshold.png");
function launch() { global $configArray; global $interface; global $user; //////////Populate the Date Filter Start $today = getdate(); //Grab the Selected Date Start if (isset($_REQUEST['dateFilterStart'])) { if (preg_match('/\\d{1,2}\\/\\d{1,2}\\/\\d{4}/', $_REQUEST['dateFilterStart'])) { $selectedDateStart = DateTime::createFromFormat('m/d/Y', $_REQUEST['dateFilterStart']); $selectedDateStart = $selectedDateStart->getTimestamp(); } else { $selectedDateStart = strtotime($_REQUEST['dateFilterStart']); } } else { $selectedDateStart = strtotime('-30 days'); } $selectedDateStart = date('Y-m-d', $selectedDateStart); $interface->assign('selectedDateStart', $selectedDateStart); //Populate the Date Filter End //Grab the Selected End Date if (isset($_REQUEST['dateFilterEnd'])) { if (preg_match('/\\d{1,2}\\/\\d{1,2}\\/\\d{4}/', $_REQUEST['dateFilterEnd'])) { $selectedDateEnd = DateTime::createFromFormat('m/d/Y', $_REQUEST['dateFilterEnd']); $selectedDateEnd = $selectedDateEnd->getTimestamp(); } else { $selectedDateEnd = strtotime($_REQUEST['dateFilterEnd']); } } else { $selectedDateEnd = strtotime('today'); } $selectedDateEnd = date('Y-m-d', $selectedDateEnd); $interface->assign('selectedDateEnd', $selectedDateEnd); //////////Populate the Stores Filter $queryStoresFilter = "SELECT DISTINCT store AS Store FROM purchase_link_tracking ORDER BY Store ASC"; $resStoresFilter = mysql_query($queryStoresFilter); $allStores = array(); $i = 0; while ($r = mysql_fetch_array($resStoresFilter)) { $allStores[] = $r['Store']; } $interface->assign('resultsStoresFilter', $allStores); //////////Grab the Selected Stores Filter Value $selectedStoresFilter = array(); if (isset($_REQUEST['storesFilter'])) { $selectedStoresFilter = $_REQUEST['storesFilter']; } else { //Pre-Populate the Stores Filter MultiSelect list $queryStoresPreSelect = "SELECT DISTINCT store AS Store FROM purchase_link_tracking\n\t\t\t\tORDER BY Store ASC"; $resStoresPreSelect = mysql_query($queryStoresPreSelect); $i = 0; while ($r = mysql_fetch_array($resStoresPreSelect)) { $selectedStoresFilter[$i++] = $r['Store']; } } $interface->assign('selectedStoresFilter', $selectedStoresFilter); $baseQueryPurchases = "SELECT COUNT(purchaseLinkId) AS Purchases, store AS Store " . "FROM purchase_link_tracking " . "WHERE (DATE_FORMAT(trackingDate, '%Y-%m-%d')) BETWEEN '" . $selectedDateStart . "' AND '" . $selectedDateEnd . "' "; if (count($selectedStoresFilter) > 0) { $stores = join("','", $selectedStoresFilter); $baseQueryPurchases .= "AND store IN ('" . $stores . "') "; } $baseQueryPurchases .= "GROUP BY store "; //////////Get a count of the page view data $queryPurchasesCount = "SELECT COUNT(*) AS RowCount from ( " . $baseQueryPurchases . ") As ResultCount"; $resPurchasesCount = mysql_query($queryPurchasesCount); $rowCount = mysql_fetch_object($resPurchasesCount); $totalResultCount = $rowCount->RowCount; //////////Create the items per page array $itemsPerPageList = array(); $itemsPerPageList = $this->getItemsPerPageList(); ///////////////////PAGING $currentPage = 1; $resultTotal = $totalResultCount; $startRecord = 1; if (isset($_GET['itemsPerPage'])) { switch ($_GET['itemsPerPage']) { case "20": $itemsPerPage = 20; $itemsPerPageList["20"]["selected"] = true; break; case "100": $itemsPerPage = 100; $itemsPerPageList["100"]["selected"] = true; break; default: $itemsPerPage = 50; $itemsPerPageList["50"]["selected"] = true; } } else { $itemsPerPage = 50; $itemsPerPageList["50"]["selected"] = true; } $endRecord = $itemsPerPage; $interface->assign('itemsPerPageList', $itemsPerPageList); if (isset($_GET['page'])) { $currentPage = $_GET['page']; // 1st record is easy, work out the start of this page $startRecord = ($currentPage - 1) * $itemsPerPage + 1; // Last record needs more care if ($resultTotal < $itemsPerPage) { // There are less records returned then one page, use total results $endRecord = $resultTotal; } else { if ($currentPage * $itemsPerPage > $resultTotal) { // The end of the curent page runs past the last record, use total results $endRecord = $resultTotal; } else { // Otherwise use the last record on this page $endRecord = $currentPage * $itemsPerPage; } } } //////////Get the Page View Data with paging and sorting if (isset($_GET['reportSort'])) { $sortValue = $_GET['reportSort']; } //////////Create a sort array $sortList = $this->getSortList(); if (isset($sortValue)) { switch ($sortValue) { case "PurchasesDESC": $baseQueryPurchases .= "ORDER BY purchases DESC "; $sortList["PurchasesDESC"]["selected"] = true; break; case "PurchasesASC": $baseQueryPurchases .= "ORDER BY purchases ASC "; $sortList["PurchasesASC"]["selected"] = true; break; case "StoreASC": $baseQueryPurchases .= "ORDER BY store ASC "; $sortList["StoreASC"]["selected"] = true; break; case "StoreDESC": $baseQueryPurchases .= "ORDER BY store DESC "; $sortList["StoreDESC"]["selected"] = true; break; default: $baseQueryPurchases .= "ORDER BY store ASC "; $sortList["StoreASC"]["selected"] = true; } } else { $baseQueryPurchases .= "ORDER BY store ASC "; } //append on a limit to return a result if (!isset($_REQUEST['exportToExcel'])) { $baseQueryPurchases .= "LIMIT " . ($startRecord - 1) . ", " . $itemsPerPage . " "; } $resPurchases = mysql_query($baseQueryPurchases); //Build an array based on the data to dump out to the grid $resultsPurchases = array(); $i = 0; while ($r = mysql_fetch_array($resPurchases)) { $tmp = array('Purchases' => $r['Purchases'], 'Store' => $r['Store']); $resultsPurchases[$i++] = $tmp; } $interface->assign('resultsPurchases', $resultsPurchases); //////////Paging Array $summary = array('page' => $currentPage, 'perPage' => $itemsPerPage, 'resultTotal' => $totalResultCount, 'startRecord' => $startRecord, 'endRecord' => $endRecord); $interface->assign('recordCount', $summary['resultTotal']); $interface->assign('recordStart', $summary['startRecord']); $interface->assign('recordEnd', $summary['endRecord']); // Process Paging using VuFind Pager object if (strrpos($_SERVER["REQUEST_URI"], "page=")) { //replace the page variable with a new one $link = str_replace("page=" . $currentPage, "page=%d", $_SERVER["REQUEST_URI"]); } else { if (strrpos($_SERVER["REQUEST_URI"], "?")) { $link = $_SERVER["REQUEST_URI"] . "&page=%d"; } else { $link = $_SERVER["REQUEST_URI"] . "?page=%d"; } } $options = array('totalItems' => $summary['resultTotal'], 'fileName' => $link, 'perPage' => $summary['perPage']); $pager = new VuFindPager($options); $interface->assign('pageLinks', $pager->getLinks()); ///////////////////END PAGING //////////Sorting $sortUrl = $_SERVER["REQUEST_URI"]; if (isset($sortValue)) { //Set the URL for sorting if (strrpos($_SERVER["REQUEST_URI"], "reportSort=")) { //replace the page variable with a new one $sortUrl = str_replace("sort=" . $currentPage, "reportSort=" . $sortValue, $_SERVER["REQUEST_URI"]); } else { if (strrpos($_SERVER["REQUEST_URI"], "?")) { $sortUrl = $_SERVER["REQUEST_URI"] . "&reportSort=" . $sortValue; } else { $sortUrl = $_SERVER["REQUEST_URI"] . "?reportSort=" . $sortValue; } } } $interface->assign('sortUrl', $sortUrl); $interface->assign('sortList', $sortList); //////////CHART //Create the chart and load data into the results. $queryDailyPurchases = "SELECT DATE_FORMAT(trackingDate, '%Y-%m-%d') as date, COUNT(recordId) AS Purchases, store AS Store FROM purchase_link_tracking " . "WHERE (DATE_FORMAT(trackingDate, '%Y-%m-%d')) BETWEEN '" . $selectedDateStart . "' AND '" . $selectedDateEnd . "' "; if (count($selectedStoresFilter) > 0) { $stores = join("','", $selectedStoresFilter); $queryDailyPurchases .= "AND store IN ('" . $stores . "') "; } $queryDailyPurchases .= "GROUP BY DATE_FORMAT(trackingDate, '%Y-%m-%d'), store ORDER BY trackingDate ASC"; $dailyPurchases = mysql_query($queryDailyPurchases); //Initialize data by loading all of the dates that we are looking at so we can show the correct counts or each series on the right day. $check_date = $selectedDateStart; $datesInReport = array(); $purchasesByStoreByDay = array(); foreach ($allStores as $storeName) { $purchasesByStoreByDay[$storeName] = array(); } $numDatesChecked = 0; //Prevent infinite loops while ($check_date != $selectedDateEnd && $numDatesChecked < 3000) { $check_date = date("Y-m-d", strtotime("+1 day", strtotime($check_date))); $datesInReport[] = $check_date; //Default number of purchases for the day to 0 foreach ($allStores as $storeName) { $purchasesByStoreByDay[$storeName][$check_date] = 0; } $numDatesChecked++; } //Chart section $reportData = new pData(); while ($r = mysql_fetch_array($dailyPurchases)) { $store = $r['Store']; $purchasesByStoreByDay[$store][$r['date']] = $r['Purchases']; } foreach ($purchasesByStoreByDay as $storeName => $dailyResults) { $reportData->addPoints($dailyResults, $storeName); } $reportData->setAxisName(0, "Purchases"); $reportData->addPoints($datesInReport, "Dates"); $reportData->setAbscissa("Dates"); /* Create the pChart object */ $myPicture = new pImage(700, 290, $reportData); /* Draw the background */ $Settings = array("R" => 225, "G" => 225, "B" => 225); $myPicture->drawFilledRectangle(0, 0, 700, 290, $Settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 699, 289, array("R" => 0, "G" => 0, "B" => 0)); $myPicture->setFontProperties(array("FontName" => "sys/pChart/Fonts/verdana.ttf", "FontSize" => 9)); $myPicture->setGraphArea(50, 30, 670, 190); //$myPicture->drawFilledRectangle(30,30,670,150,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10)); $myPicture->drawScale(array("DrawSubTicks" => TRUE, "LabelRotation" => 90)); $myPicture->setFontProperties(array("FontName" => "sys/pChart/Fonts/verdana.ttf", "FontSize" => 9)); $myPicture->drawLineChart(array("DisplayValues" => TRUE, "DisplayColor" => DISPLAY_AUTO)); /* Write the chart legend */ $myPicture->drawLegend(80, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */ $time = time(); $chartHref = "/images/charts/dailyPurchases{$time}.png"; $chartPath = $configArray['Site']['local'] . $chartHref; $myPicture->render($chartPath); $interface->assign('chartPath', $chartHref); //EXPORT To EXCEL if (isset($_REQUEST['exportToExcel'])) { //PHPEXCEL // Create new PHPExcel object $objPHPExcel = new PHPExcel(); // Set properties $objPHPExcel->getProperties()->setCreator("DCL")->setLastModifiedBy("DCL")->setTitle("Office 2007 XLSX Document")->setSubject("Office 2007 XLSX Document")->setDescription("Office 2007 XLSX, generated using PHP.")->setKeywords("office 2007 openxml php")->setCategory("Purchases Report"); // Add some data $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Purchases Report')->setCellValue('A3', 'STORE')->setCellValue('B3', 'PURCHASES'); $a = 4; //Loop Through The Report Data foreach ($resultsPurchases as $resultsPurchases) { $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $a, $resultsPurchases['Store'])->setCellValue('B' . $a, $resultsPurchases['Purchases']); $a++; } $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true); // Rename sheet $objPHPExcel->getActiveSheet()->setTitle('Purchases'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Redirect output to a client's web browser (Excel5) header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="PurchaseLinkReport.xls"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; } $interface->setPageTitle('Report - Purchase Tracking'); $interface->setTemplate('reportPurchase.tpl'); $interface->display('layout.tpl'); }
protected function render_graph($title, pData $MyData, $zoom, $width = 0, $height = 0) { // Check graph size sanity $width = intval($width); if ($width <= 50 || $width > 4096) { $width = 700; } $height = intval($height); if ($height <= 60 || $height > 4096) { $height = 260; } $MyData->setSerieDescription("TimeStamp", "time"); $MyData->setAbscissa("TimeStamp"); switch ($zoom) { case 'hour': $MyData->setXAxisDisplay(AXIS_FORMAT_TIME, "H:00"); break; case 'year': $MyData->setXAxisDisplay(AXIS_FORMAT_DATE, "Y"); break; case 'month': $MyData->setXAxisDisplay(AXIS_FORMAT_DATE, "Y-m"); break; case 'day': $MyData->setXAxisDisplay(AXIS_FORMAT_DATE, "Y-m-d"); break; } /* Create the pChart object */ $myPicture = new pImage($width, $height, $MyData); /* Turn of Antialiasing */ $myPicture->Antialias = FALSE; /* Draw a background */ $Settings = array("R" => 90, "G" => 90, "B" => 90, "Dash" => 1, "DashR" => 120, "DashG" => 120, "DashB" => 120); $myPicture->drawFilledRectangle(0, 0, $width, $height, $Settings); /* Overlay with a gradient */ $Settings = array("StartR" => 200, "StartG" => 200, "StartB" => 200, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, $width, $height, DIRECTION_VERTICAL, $Settings); $myPicture->drawGradientArea(0, 0, $width, $height, DIRECTION_HORIZONTAL, $Settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, $width - 1, $height - 1, array("R" => 0, "G" => 0, "B" => 0)); /* Write the chart title */ $myPicture->setFontProperties(array("FontName" => AmpConfig::get('prefix') . "/modules/pChart/fonts/Forgotte.ttf", "FontSize" => 11)); $myPicture->drawText(150, 35, $title, array("FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => AmpConfig::get('prefix') . "/modules/pChart/fonts/pf_arma_five.ttf", "FontSize" => 6)); /* Define the chart area */ $myPicture->setGraphArea(60, 40, $width - 20, $height - 50); /* Draw the scale */ $scaleSettings = array("XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 200, "RemoveSkippedAxis" => TRUE, "DrawSubTicks" => FALSE, "Mode" => SCALE_MODE_START0, "LabelRotation" => 45, "LabelingMethod" => LABELING_DIFFERENT); $myPicture->drawScale($scaleSettings); /* Turn on Antialiasing */ $myPicture->Antialias = TRUE; /* Draw the line chart */ $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); $myPicture->drawLineChart(); /* Write a label over the chart */ $myPicture->writeLabel("Inbound", 720); /* Write the chart legend */ $myPicture->drawLegend(280, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); header("Content-Disposition: filename=\"ampache-graph.png\""); /* Render the picture (choose the best way) */ $myPicture->autoOutput(); }
public function reportday($projectID) { /* pChart library inclusions */ include "../p_chart/class/pData.class.php"; include "../p_chart/class/pDraw.class.php"; include "../p_chart/class/pImage.class.php"; //每日剩余 $where = "project = {$projectID} AND deleted = '0' AND status NOT IN ( 'cancel','closed') "; $tasks_all = $this->task->getTasksByCondition($where); $tasks_all_count = count($tasks_all); $this->view->tasks_all_count = $tasks_all_count; $where = "project = {$projectID} AND deleted = '0'"; $allFinishedDate = $this->task->getAllFinishedDate($where); $tasks_un_finished_x = array(); $tasks_un_finished_y = array(); foreach (array_reverse($allFinishedDate) as $v) { $where = "project = {$projectID} AND deleted = '0' AND status NOT IN ( 'cancel','closed') AND finishedDate <= '{$v->date} 23:59:59' AND finishedDate != '0000-00-00 00:00:00'"; $count = $this->task->getUnFinishedTasksPerDay($where, $tasks_all_count); $tasks_un_finished_x[] = date('m-d', strtotime($v->date)); $tasks_un_finished_y[] = $count; } /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints($tasks_un_finished_y, "Probe 1"); $MyData->setSerieWeight("Probe 1", 2); $MyData->setAxisName(0, ""); $MyData->addPoints($tasks_un_finished_x, "Labels"); $MyData->setSerieDescription("Labels", "Months"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(700, 230, $MyData); /* Turn of Antialiasing */ $myPicture->Antialias = FALSE; /* Draw the background */ $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107); $myPicture->drawFilledRectangle(0, 0, 700, 230, $Settings); /* Overlay with a gradient */ $Settings = array("StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $Settings); $myPicture->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80)); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0)); /* Write the chart title */ $myPicture->setFontProperties(array("FontName" => "../p_chart/fonts/msyh.ttf", "FontSize" => 8, "R" => 255, "G" => 255, "B" => 255)); $myPicture->drawText(10, 16, "每日剩余任务数", array("FontSize" => 10, "Align" => TEXT_ALIGN_BOTTOMLEFT)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => "../p_chart/fonts/msyh.ttf", "FontSize" => 8, "R" => 0, "G" => 0, "B" => 0)); /* Define the chart area */ $myPicture->setGraphArea(60, 40, 650, 200); /* Draw the scale */ $scaleSettings = array("XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE); $myPicture->drawScale($scaleSettings); /* Turn on Antialiasing */ $myPicture->Antialias = TRUE; /* Enable shadow computing */ $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); /* Draw the line chart */ $myPicture->drawLineChart(); $myPicture->drawPlotChart(array("DisplayValues" => TRUE, "PlotBorder" => TRUE, "BorderSize" => 2, "Surrounding" => -60, "BorderAlpha" => 80)); /* Write the chart legend */ $myPicture->drawLegend(590, 9, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL, "FontR" => 255, "FontG" => 255, "FontB" => 255)); /* Render the picture (choose the best way) */ $myPicture->autoOutput(); $img = $myPicture->base64("output.png"); $this->view->src_line = $img; //每位成员剩余 $where = "project = {$projectID} AND deleted = '0' AND (status = 'wait' OR status = 'doing') AND assignedTo !='' "; $tasks_un_finished_per_member = $this->task->getUnFinishedTasksPerAssignedTo($where); $tasks_un_finished_member_x = array(); $tasks_un_finished_member_y = array(); foreach ($tasks_un_finished_per_member as $v) { $tasks_un_finished_member_x[] = $v->value; $tasks_un_finished_member_y[] = $v->name; } /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints($tasks_un_finished_member_x, "Hits"); $MyData->setAxisName(0, "剩余任务数"); $MyData->addPoints($tasks_un_finished_member_y, "Browsers"); $MyData->setSerieDescription("Browsers", "Browsers"); $MyData->setAbscissa("Browsers"); //$MyData->setAbscissaName("Browsers"); /* Create the pChart object */ $myPicture = new pImage(500, 500, $MyData); $myPicture->drawGradientArea(0, 0, 500, 500, DIRECTION_VERTICAL, array("StartR" => 240, "StartG" => 240, "StartB" => 240, "EndR" => 180, "EndG" => 180, "EndB" => 180, "Alpha" => 100)); $myPicture->drawGradientArea(0, 0, 500, 500, DIRECTION_HORIZONTAL, array("StartR" => 240, "StartG" => 240, "StartB" => 240, "EndR" => 180, "EndG" => 180, "EndB" => 180, "Alpha" => 20)); $myPicture->setFontProperties(array("FontName" => "../p_chart/fonts/msyh.ttf", "FontSize" => 8)); /* Draw the chart scale */ $myPicture->setGraphArea(100, 30, 480, 480); $myPicture->drawScale(array("CycleBackground" => TRUE, "DrawSubTicks" => TRUE, "GridR" => 0, "GridG" => 0, "GridB" => 0, "GridAlpha" => 10, "Pos" => SCALE_POS_TOPBOTTOM)); /* Turn on shadow computing */ $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); /* Create the per bar palette */ $Palette = array("0" => array("R" => 188, "G" => 224, "B" => 46, "Alpha" => 100), "1" => array("R" => 224, "G" => 100, "B" => 46, "Alpha" => 100), "2" => array("R" => 224, "G" => 214, "B" => 46, "Alpha" => 100), "3" => array("R" => 46, "G" => 151, "B" => 224, "Alpha" => 100), "4" => array("R" => 176, "G" => 46, "B" => 224, "Alpha" => 100), "5" => array("R" => 224, "G" => 46, "B" => 117, "Alpha" => 100), "6" => array("R" => 92, "G" => 224, "B" => 46, "Alpha" => 100), "7" => array("R" => 224, "G" => 176, "B" => 46, "Alpha" => 100)); /* Draw the chart */ $myPicture->drawBarChart(array("DisplayPos" => LABEL_POS_INSIDE, "DisplayValues" => TRUE, "Rounded" => TRUE, "Surrounding" => 30, "OverrideColors" => $Palette)); /* Write the legend */ $myPicture->drawLegend(570, 215, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */ $myPicture->autoOutput(); $img = $myPicture->base64("output.png"); $this->view->src_bar = $img; $project_info = $this->loadModel('project')->getById($projectID); $this->view->project_info = $project_info; //今日完成 $where = "project = {$projectID} AND deleted = '0' AND status = 'done' AND DATE_FORMAT(finishedDate,'%Y-%m-%d') = '" . date('Y-m-d') . "'"; $tasks_done_today = $this->task->getTasksByCondition($where); $this->view->tasks_done_today = $tasks_done_today; //今日新增 $where = "project = {$projectID} AND deleted = '0' AND DATE_FORMAT(openedDate,'%Y-%m-%d') = '" . date('Y-m-d') . "'"; $tasks_opened_today = $this->task->getTasksByCondition($where); $this->view->tasks_opened_today = $tasks_opened_today; //未完成(迭代期) $where = "project = {$projectID} AND deleted = '0' AND (status = 'wait' OR status = 'doing')"; $tasks_un_finished = $this->task->getTasksByCondition($where); $this->view->tasks_un_finished = $tasks_un_finished; $this->display($this->moduleName, 'reportday'); }