public function _showGraph_pChart($buscarBarra) { // Dataset definition $DataSet = new pData(); if ($buscarBarra == "semana") { $semana = array("1era Semana", "2da Semana", "3era Semana", "4ta Semana"); $cantidadSemanal = array(2, 4, 5, 6); $DataSet->AddPoint($semana, "Serie1"); $DataSet->AddPoint($cantidadSemanal, "Serie2"); // Initialise the graph define("WIDTH", 500); define("HEIGHT", 500); $Test = new pChart(WIDTH, HEIGHT); $Test->setFontProperties("../font/arial.ttf", 7); $Test->setGraphArea(40, 30, WIDTH - 30, HEIGHT - 30); $Test->drawFilledRoundedRectangle(7, 7, WIDTH - 7, HEIGHT - 7, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, WIDTH - 5, HEIGHT - 5, 5, 230, 230, 230); } elseif ($buscarBarra == "mes") { $mensual = array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Setiembre", "Octubre"); $cantidadMensual = array(4, 6, 11, 23, 9, 2, 30, 20, 12, 45); $DataSet->AddPoint($mensual, "Serie1"); $DataSet->AddPoint($cantidadMensual, "Serie2"); // Initialise the graph define("WIDTH", 700); define("HEIGHT", 500); $Test = new pChart(WIDTH, HEIGHT); $Test->setFontProperties("../font/arial.ttf", 7); $Test->setGraphArea(40, 30, WIDTH - 30, HEIGHT - 30); $Test->drawFilledRoundedRectangle(7, 7, WIDTH - 7, HEIGHT - 7, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, WIDTH - 5, HEIGHT - 5, 5, 230, 230, 230); $Test->setColorPalette(0, 224, 100, 46); } $DataSet->AddAllSeries(); $DataSet->RemoveSerie("Serie1"); $DataSet->SetAbsciseLabelSerie("Serie1"); $DataSet->SetSerieName("Productos Comprados", "Serie2"); // Initialise the graph $Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 0, 2, TRUE); $Test->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line $Test->setFontProperties("../font/arial.ttf", 6); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the bar graph $Test->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 70); // Set labels $Test->setFontProperties("../font/arial.ttf", 7); $Test->writeValues($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie2"); // Finish the graph $Test->setFontProperties("../font/arial.ttf", 8); $Test->drawLegend(WIDTH / 5, 25, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties("../font/arial.ttf", 10); $Test->drawTitle(WIDTH - 200, 22, "Estadistica de Barra de Grafico", 50, 50, 50, 185); $Test->Render("../img/imagenBarra_pChart.png"); }
/** * Display chart directly * @return unknown */ public function show() { if (empty($this->cdata)) { require_once 'Hush/Chart/Exception.php'; throw new Hush_Chart_Exception('Empty data exception, please add data first'); } $this->showValue('score'); $method = 'draw' . ucfirst($this->type); if (method_exists($this, $method)) { $this->{$method}(); // insert show serie logic if (count($this->shows) > 0) { foreach ($this->shows as $serie) { $this->chart->writeValues($this->data->GetData(), $this->data->GetDataDescription(), $serie); } } $this->chart->Stroke(); } }
function stacked($data, $title, $filename) { // Dataset definition $DataSet = new pData(); $values = $data['values']; $bar = new pChart(1040, 230); for ($i = 0; $i < count($values); $i++) { $DataSet->AddPoint($values[$i], "Serie" . ($i + 1)); if ($i != 0 && $i != count($values) - 1) { $DataSet->AddSerie("Serie" . ($i + 1)); } } $DataSet->SetAbsciseLabelSerie("Serie1"); $DataSet->SetXAxisFormat("date"); $DataSet->SetYAxisFormat($data['yformat']); // Initialise the graph $bar->setDateFormat("M.d"); $bar->setFontProperties("Fonts/consola.ttf", 8); $bar->setGraphArea(80, 30, 1020, 200); $bar->drawFilledRoundedRectangle(2, 2, 1037, 227, 5, 240, 240, 240); $bar->drawRoundedRectangle(0, 0, 1039, 229, 5, 230, 230, 230); $bar->loadColorPalette('chartcolors.txt', ','); $bar->drawGraphArea(255, 255, 255, TRUE); $bar->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALL, 150, 150, 150, TRUE, 0, 2, TRUE); $bar->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line $bar->setFontProperties("Fonts/consola.ttf", 6); $bar->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the bar graph $bar->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 100); $bar->setFontProperties("Fonts/tahoma.ttf", 8); $bar->writeValues($DataSet->GetData(), $DataSet->GetDataDescription(), array("Serie" . count($values))); // Finish the graph $bar->setFontProperties("Fonts/MankSans.ttf", 10); $bar->drawTitle(10, 20, $title, 100, 100, 100); $bar->Render($filename); }
function generate_graph_image($outputfile) { // Create Graph Dataset and set axis attributes $graphData = new pData(); $graphData->setYAxisName($this->ytitle); $graphData->AddPoint($this->xlabels, "xaxis"); //$graphData->SetSerieName("xaxis","xaxis"); $graphData->SetAbsciseLabelSerie("xaxis"); $graphData->setXAxisName($this->xtitle); // 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->AddPoint($v["data"], $series); $graphData->SetSerieName($v["legend"], $series); $graphData->AddSerie($series); } /* 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($this->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 $this->width_pdf_actual.",".$this->height_pdf_actual."<BR>"; $graphImage = new pChart($this->width_pdf_actual, $this->height_pdf_actual); /* Turn of Antialiasing */ $graphImage->Antialias = TRUE; // Add gradient fill from chosen background color to white $startgradient = htmltorgb("#ffffff"); //$graphImage->drawGradientArea(0,0,$width,$height,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,$width - 1,$height - 1,200,200,200); $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xaxisfont, $this->xaxisfontsize); /* Define the chart area */ $graphImage->setGraphArea($this->marginleft_actual, $this->margintop_actual, $this->width_pdf_actual - $this->marginright_actual, $this->height_pdf_actual - $this->marginbottom_actual); $graphImage->drawFilledRoundedRectangle(3, 3, $this->width_pdf_actual - 3, $this->height_pdf_actual - 3, 5, 240, 240, 240); $graphImage->drawRoundedRectangle(1, 1, $this->width_pdf_actual - 1, $this->height_pdf_actual - 1, 5, 230, 230, 230); // Before plotting a series ensure they are all not drawable. /// Plot the chart data $stackeddrawn = false; $linedrawn = false; $scatterdrawn = false; $piedrawn = false; $stackedexists = false; $overlayexists = false; $barexists = false; foreach ($this->plot as $k => $v) { if ($v["type"] == "OVERLAYBAR") { $overlayexists = true; } if ($v["type"] == "STACKEDBAR") { $stackedexists = true; } if ($v["type"] == "STACKEDBAR" || $v["type"] == "BAR") { $barexists = true; } // Set plot colors if ($v["linecolor"]) { $graphImage->Palette[$k] = htmltorgb_pchart($v["linecolor"]); } $url .= "&plotlinecolor{$k}=" . $v["linecolor"]; } $scale_drawing_mode = SCALE_NORMAL; $scale_drawing_mode = SCALE_START0; // For stacked charts fix up the Max and Min values; if ($stackedexists) { $scale_drawing_mode = SCALE_ADDALL; $scaleMin = "Unknown"; $scaleMax = 0; $min = false; $max = false; foreach ($plot as $k => $v) { if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") { $series = $v["name"] . $k; minmaxValueOfSeries($v["data"], $min, $max); if ($scaleMin == "Unknown" || $min < $scaleMin) { $scaleMin = $min; } $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)); } else { if ($barexists || $overlayexists) { $scaleMin = "Unknown"; $scaleMax = 0; $min = false; $max = false; foreach ($this->plot as $k => $v) { if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") { $series = $v["name"] . $k; minmaxValueOfSeries($v["data"], $min, $max); if ($scaleMin == "Unknown" || $min < $scaleMin) { $scaleMin = $min; } 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)); } } //echo "<PRE>"; //var_dump($graphData->GetDataDescription()); //die; // Find out if a scale is required, will be except for pie charts $scalerequired = false; foreach ($this->plot as $k => $v) { switch ($v["type"]) { case "BAR": case "STACKEDBAR": case "OVERLAYBAR": case "LINE": $scalerequired = "NORMAL"; break; case "SCATTER": $scalerequired = "SCATTER"; break; } } $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xtitlefont, $this->xtitlefontsize); if ($scalerequired) { $graphImage->setGraphArea($this->marginleft_actual, $this->margintop_actual, $this->width_pdf_actual - $this->marginright, $this->height_pdf_actual - $this->marginbottom_actual); $graphImage->drawGraphAreaGradient(240, 240, 240, -20); // Automatic generation of x tick interval based on number of ticks if ($this->xticklabelinterval_actual == "AUTO") { $labct = count($this->plot[0]["data"]); $this->xticklabelinterval_actual = floor($labct / 35) + 1; } if ($scalerequired == "NORMAL") { $graphImage->drawScale($graphData->GetData(), $graphData->GetDataDescription(), $scale_drawing_mode, 0, 0, 0, TRUE, 40, FALSE, TRUE, $this->xticklabelinterval_actual, FALSE); } $graphImage->drawGrid(2, TRUE, 230, 230, 230, 45); } else { $this->marginright = 5; $this->marginbottom = 5; $this->marginleft = 5; $this->marginright_actual = 5; $this->marginbottom_actual = 5; $this->marginleft_actual = 5; //$this->margintop_actual = 5; $graphImage->setGraphArea($this->marginleft, $this->margintop_actual, $this->width_pdf_actual - $this->marginright, $this->height_pdf_actual - $this->marginbottom); $graphImage->drawGraphAreaGradient(240, 240, 240, -10); } // If there's a Pie chart we want to draw different legends $piechart = false; foreach ($this->plot as $k => $v) { disableAllSeries($this->plot, $graphData); $series = $v["name"] . $k; setSerieDrawable($this->plot, $graphData, $series, TRUE); switch ($v["type"]) { case "PIE": $piedrawn = true; $piechart = true; $graphImage->drawFilledCircle($this->width_pdf_actual / 2 + 2, $this->margintop_actual + 2 + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.45 + 1, 200, 200, 200); $graphImage->drawBasicPieGraph($graphData->GetData(), $graphData->GetDataDescription(), $this->width_pdf_actual / 2, $this->margintop_actual + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.45, PIE_PERCENTAGE_LABEL, 255, 255, 218); break; case "PIE3D": $piedrawn = true; $piechart = true; $graphImage->drawPieGraph($graphData->GetData(), $graphData->GetDataDescription(), $this->width_pdf_actual / 2, $this->margintop_actual + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.5, PIE_PERCENTAGE_LABEL, true, 60, 20, 0, 0); break; case "OVERLAYBAR": case "STACKEDBAR": case "BAR": if ($stackeddrawn) { break; } if ($barexists || $overlayexists) { foreach ($this->plot as $k1 => $v1) { if ($v1["type"] == "BAR" || $v1["type"] == "STACKEDBAR" || $v1["type"] == "OVERLAYBAR") { setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE); } } } $stackeddrawn = true; if ($stackedexists) { $graphImage->drawStackedBarGraph($graphData->GetData(), $graphData->GetDataDescription(), 90); } else { if ($overlayexists) { $graphImage->drawOverlayBarGraph($graphData->GetData(), $graphData->GetDataDescription(), 90); } else { $graphImage->drawBarGraph($graphData->GetData(), $graphData->GetDataDescription()); } } break; case "SCATTER": if ($scatterdrawn) { break; } $scatterdrawn = true; $series1 = false; $series2 = false; $graphImage->reportWarnings("GD"); $ct = 0; foreach ($this->plot as $k1 => $v1) { if ($v1["type"] == "SCATTER") { if ($ct == 0) { $series1 = $v1["name"] . $k1; } if ($ct == 1) { $series2 = $v1["name"] . $k1; } $ct++; setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE); } } if (count($v["data"]) == 1) { $v["data"][] = 0; } $graphImage->drawXYScale($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2, 0, 0, 0); //$graphImage->drawXYGraph($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2); $graphImage->drawXYPlotGraph($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2); $graphImage->writeValues($graphData->GetData(), $graphData->GetDataDescription(), $series2); break; case "LINE": default: if ($linedrawn) { break; } $linedrawn = true; foreach ($this->plot as $k1 => $v1) { if ($v1["type"] == "LINE") { setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE); } } if (count($v["data"]) == 1) { $v["data"][] = 0; } $graphImage->LineWidth = 1; $graphImage->drawLineGraph($graphData->GetData(), $graphData->GetDataDescription()); $graphImage->drawPlotGraph($graphData->GetData(), $graphData->GetDataDescription()); $graphImage->LineWidth = 1; break; } } foreach ($this->plot as $k1 => $v1) { setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE); } // Draw Legend if legend value has been set $drawlegend = false; foreach ($this->plot as $k => $v) { if (isset($v["legend"]) && $v["legend"]) { // Temporarily Dont draw legend for Pie //if ( $piechart ) //$graphImage->drawPieLegend($this->width_pdf_actual - 180,30,$graphData->GetData(), $graphData->GetDataDescription(), 250, 250, 250); if (!$piechart) { $graphImage->drawLegend($this->width_pdf_actual - 120, 30, $graphData->GetDataDescription(), 254, 254, 254, 0, 0, 0); } break; } } $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xtitlefont, $this->titlefontsize); $graphImage->drawTitle(0, 24, $this->title_actual, 50, 50, 50, $this->width_pdf_actual); //$graphImage->setShadow(TRUE,array("X"=>0,"Y"=>0,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); //$graphImage->Render("example.png"); //$graphImage->Stroke(); $graphImage->render($outputfile); return true; }
$DataSet->AddSerie("Serie1"); $DataSet->AddSerie("Serie2"); $DataSet->SetAbsciseLabelSerie("Serie3"); $DataSet->SetSerieName("Amount", "Serie1"); $DataSet->SetSerieName("Control ({$minquoteamtinmonth})", "Serie2"); $DataSet->SetYAxisName("Amount({$defcurrencycode})"); // $DataSet->SetYAxisUnit("RM"); $Test = new pChart(600, 230); $Test->setFontProperties("../simantz/class/pchart/Fonts/tahoma.ttf", 8); $Test->setGraphArea(65, 30, 550, 200); $Test->drawFilledRoundedRectangle(7, 7, 593, 223, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 595, 225, 5, 230, 230, 230); $Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE); $Test->drawGrid(4, TRUE, 230, 230, 230, 50); $Test->writeValues($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie1"); // Draw the title $Test->setFontProperties("../simantz/class/pchart/Fonts/pf_arma_five.ttf", 8); $Title = "QUotation Amount Vs Time For {$defaultorganization_name}"; $Test->drawTextBox(65, 10, 550, 25, $Title, 0, 255, 255, 255, ALIGN_CENTER, TRUE, 0, 0, 0, 30); // Draw the line graph $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 254, 254, 254); // Draw the legend $Test->setFontProperties("../simantz/class/pchart/Fonts/tahoma.ttf", 8); $Test->drawLegend(10, 150, $DataSet->GetDataDescription(), 254, 254, 254); // Render the chart $photofile = $uploadpath . "chartsalequoteamt_6month.png"; $Test->Render($photofile); // $chart->setTitle("Sales Vs Expenses For $defaultorganization_name"); // $chart->getPlot()->setGraphCaptionRatio(0.62);
$series1 = $v1["name"] . $k1; } if ($ct == 1) { $series2 = $v1["name"] . $k1; } $ct++; setSerieDrawable($plot, $graphData, $v1["name"] . $k1, TRUE); } } if (count($v["data"]) == 1) { $v["data"][] = 0; } $graphImage->drawXYScale($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2, 0, 0, 0); //$graphImage->drawXYGraph($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2); $graphImage->drawXYPlotGraph($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2); $graphImage->writeValues($graphData->GetData(), $graphData->GetDataDescription(), $series2); break; case "LINE": default: if ($linedrawn) { break; } $linedrawn = true; foreach ($plot as $k1 => $v1) { if ($v1["type"] == "LINE") { setSerieDrawable($plot, $graphData, $v1["name"] . $k1, TRUE); } } if (count($v["data"]) == 1) { $v["data"][] = 0; }
/** * This method return a graph containing information about evaluations * inside courses in sessions, it's used inside get_block method for * showing it inside dashboard interface * @return string img html */ public function get_evaluations_courses_in_sessions_graph() { $graphs = array(); if (!empty($this->sessions)) { $session_ids = array_keys($this->sessions); foreach ($session_ids as $session_id) { $courses_code = array_keys(Tracking::get_courses_list_from_session($session_id)); $courses_graph = array(); foreach ($courses_code as $course_code) { $cats = Category::load(null, null, $course_code, null, null, $session_id); if (isset($cats) && isset($cats[0])) { $alleval = $cats[0]->get_evaluations(null, true, $course_code); $alllinks = $cats[0]->get_links(null, true); $users = get_all_users($alleval, $alllinks); $datagen = new FlatViewDataGenerator ($users, $alleval, $alllinks); $evaluation_sumary = $datagen->get_evaluation_sumary_results(); if (!empty($evaluation_sumary)) { $items = array_keys($evaluation_sumary); $max = $min = $avg = array(); foreach ($evaluation_sumary as $evaluation) { $max[] = $evaluation['max']; $min[] = $evaluation['min']; $avg[] = $evaluation['avg']; } // Dataset definition $data_set = new pData; $data_set->AddPoint($max, "Max"); $data_set->AddPoint($avg, "Avg"); $data_set->AddPoint($min, "Min"); $data_set->AddPoint($items, "Items"); $data_set->SetXAxisName(get_lang('EvaluationName')); $data_set->SetYAxisName(get_lang('Percentage')); $data_set->AddAllSeries(); $data_set->RemoveSerie("Items"); $data_set->SetAbsciseLabelSerie("Items"); $graph_id = $this->user_id.'StudentEvaluationGraph'; $cache = new pCache(); // the graph id $data = $data_set->GetData(); if ($cache->IsInCache($graph_id, $data)) { //if we already created the img $img_file = $cache->GetHash($graph_id, $data); } else { // Initialise the graph $angle = -30; $test = new pChart($this->bg_width, $this->bg_height); $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8); $test->fixHeightByRotation( $data_set->GetData(), $data_set->GetDataDescription(), $angle ); $test->setGraphArea(50, 30, $this->bg_width - 75, $this->bg_height - 75); $test->drawFilledRoundedRectangle( 7, 7, $this->bg_width - 20, $test->YSize - 20, 5, 240, 240, 240 ); $test->drawRoundedRectangle( 5, 5, $this->bg_width - 18, $test->YSize - 18, 5, 230, 230, 230 ); $test->drawGraphArea(255,255,255,TRUE); $test->setFixedScale(0,100,5); $test->drawScale( $data_set->GetData(), $data_set->GetDataDescription(), SCALE_ADDALL, 150, 150, 150, TRUE, $angle, 2, TRUE ); $test->setColorPalette(0,105,221,34); $test->setColorPalette(1,255,135,30); $test->setColorPalette(2,255,0,0); $test->drawGrid(4,TRUE,230,230,230,50); // Draw the 0 line $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',6); $test->drawTreshold(0,143,55,72,TRUE,TRUE); // Draw the bar graph $test->drawOverlayBarGraph($data_set->GetData(),$data_set->GetDataDescription(), 100); // Finish the graph $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8); $test->drawLegend($this->bg_width-80,20,$data_set->GetDataDescription(),255,255,255); $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',10); $test->setColorPalette(0,50,50,50); $test->setColorPalette(1,50,50,50); $test->setColorPalette(2,50,50,50); $test->writeValues($data_set->GetData(),$data_set->GetDataDescription(),array("Min", "Max", "Avg")); $cache->WriteToCache($graph_id, $data_set->GetData(), $test); ob_start(); $test->Stroke(); ob_end_clean(); $img_file = $cache->GetHash($graph_id, $data_set->GetData()); } if (!empty($img_file)) { $courses_graph[$course_code] = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">'; } } } } if (!empty($courses_graph)) { $graphs[$session_id] = $courses_graph; } } } return $graphs; }
public function testDrawArea() { // Dataset definition $DataSet = new pData(); $DataSet->addPoints(array(10, 9.4, 7.7, 5, 1.7, -1.7, -5, -7.7, -9.4, -10, -9.4, -7.7, -5, -1.8, 1.7), "Serie1"); $DataSet->addPoints(array(0, 3.4, 6.4, 8.699999999999999, 9.800000000000001, 9.800000000000001, 8.699999999999999, 6.4, 3.4, 0, -3.4, -6.4, -8.6, -9.800000000000001, -9.9), "Serie2"); $DataSet->addPoints(array(7.1, 9.1, 10, 9.699999999999999, 8.199999999999999, 5.7, 2.6, -0.9, -4.2, -7.1, -9.1, -10, -9.699999999999999, -8.199999999999999, -5.8), "Serie3"); $DataSet->addPoints(array("Jan", "Jan", "Jan", "Feb", "Feb", "Feb", "Mar", "Mar", "Mar", "Apr", "Apr", "Apr", "May", "May", "May"), "Serie4"); $DataSet->AddAllSeries(); $DataSet->SetAbscissaLabelSeries("Serie4"); $DataSet->SetSeriesName("Max Average", "Serie1"); $DataSet->SetSeriesName("Min Average", "Serie2"); $DataSet->SetSeriesName("Temperature", "Serie3"); $DataSet->SetYAxisName("Temperature"); $DataSet->SetXAxisName("Month of the year"); // Initialise the graph $canvas = new TestCanvas(); $Test = new pChart(700, 230, $canvas); $Test->reportWarnings("GD"); $Test->setFixedScale(-12, 12, 5); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(65, 30, 570, 185); $canvas->drawFilledRoundedRectangle(new Point(7, 7), new Point(693, 223), 5, new Color(240), 1, 0, ShadowProperties::NoShadow()); $backgroundStyle = new BackgroundStyle(new Color(255), TRUE); $Test->drawGraphBackground($backgroundStyle); $scaleStyle = new ScaleStyle(SCALE_NORMAL, new Color(150)); $Test->drawScale($DataSet, $scaleStyle, 0, 2, TRUE, 3); $Test->drawGrid(new GridStyle(4, TRUE, new Color(230), 50)); // Draw the 0 line $Test->setFontProperties("Fonts/tahoma.ttf", 6); $Test->drawTreshold(0, new Color(143, 55, 72), TRUE, TRUE); // Draw the area $DataSet->RemoveSeries("Serie4"); $Test->drawArea($DataSet->GetData(), "Serie1", "Serie2", new Color(239, 238, 227), 50); $DataSet->RemoveSeries("Serie3"); $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); // Draw the line graph $Test->setLineStyle(1, 6); $DataSet->RemoveAllSeries(); $DataSet->AddSeries("Serie3"); $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, new Color(255)); // Write values on Serie3 $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->writeValues($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie3"); // Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->drawLegend(590, 90, $DataSet->GetDataDescription(), new Color(255)); $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Test->drawTitle(60, 22, "example 15", new Color(50), 585); // Add an image $Test->drawFromPNG(dirname(__FILE__) . "/../Sample/logo.png", 584, 35); $this->assertEquals('53b34d556af518230b7556e19349bd94', md5($canvas->getActionLog())); }
/** * This method return a content html, it's used inside get_block method for showing it inside dashboard interface * @return string content html */ public function get_teachers_information_graph() { $teachers = $this->teachers; $graph = ''; $user_ids = array_keys($teachers); $a_last_week = get_last_week(); if (is_array($user_ids) && count($user_ids) > 0) { $data_set = new pData(); foreach ($user_ids as $user_id) { $teacher_info = api_get_user_info($user_id); $username = $teacher_info['username']; $time_by_days = array(); foreach ($a_last_week as $day) { // day is received as y-m-d 12:00:00 $start_date = api_get_utc_datetime($day); $end_date = api_get_utc_datetime($day + (3600 * 24 - 1)); $time_on_platform_by_day = Tracking::get_time_spent_on_the_platform($user_id, 'custom', $start_date, $end_date); $hours = floor($time_on_platform_by_day / 3600); $min = floor(($time_on_platform_by_day - $hours * 3600) / 60); $time_by_days[] = $min; } $data_set->AddPoint($time_by_days, $username); $data_set->AddSerie($username); } $last_week = date('Y-m-d', $a_last_week[0]) . ' ' . get_lang('To') . ' ' . date('Y-m-d', $a_last_week[6]); $days_on_week = array(); foreach ($a_last_week as $weekday) { $days_on_week[] = date('d/m', $weekday); } $data_set->AddPoint($days_on_week, "Days"); $data_set->SetXAxisName($last_week); $data_set->SetYAxisName(get_lang('Minutes')); $data_set->SetAbsciseLabelSerie("Days"); $graph_id = $this->user_id . 'TeacherConnectionsGraph'; $cache = new pCache(); // the graph id $data = $data_set->GetData(); if ($cache->IsInCache($graph_id, $data_set->GetData())) { //if we already created the img $img_file = $cache->GetHash($graph_id, $data_set->GetData()); } else { // Initializing the graph $bg_width = 440; $bg_height = 350; $test = new pChart($bg_width + 10, $bg_height + 20); $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8); $test->setGraphArea(65, 30, $bg_width - 70, $bg_height - 50); $test->drawFilledRoundedRectangle(7, 7, $bg_width, $bg_height, 5, 240, 240, 240); $test->drawRoundedRectangle(5, 5, $bg_width + 2, $bg_height + 2, 5, 230, 230, 230); $test->drawGraphArea(255, 255, 255, TRUE); $test->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE); $test->drawGrid(4, TRUE, 230, 230, 230, 50); // Drawing lines //$test->drawLineGraph($data_set->GetData(),$data_set->GetDataDescription()); $test->drawFilledCubicCurve($data_set->GetData(), $data_set->GetDataDescription(), 0.1, 30); //$test->drawPlotGraph($data_set->GetData(),$data_set->GetDataDescription(),3,2,255,255,255); // Drawing Legend $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8); $test->drawLegend($bg_width - 80, 20, $data_set->GetDataDescription(), 204, 204, 255); $test->writeValues($data_set->GetData(), $data_set->GetDataDescription(), array("Days")); $cache->WriteToCache($graph_id, $data_set->GetData(), $test); ob_start(); $test->Stroke(); ob_end_clean(); $img_file = $cache->GetHash($graph_id, $data_set->GetData()); } if (!empty($img_file)) { $graph = '<img src="' . api_get_path(WEB_ARCHIVE_PATH) . $img_file . '">'; } } else { $graph = '<p>' . api_convert_encoding(get_lang('GraphicNotAvailable'), 'UTF-8') . '</p>'; } return $graph; }
/** * Creates the object and prepares it for rendering. * Does all the calculation like borders, margins, paddings .... * * @return void */ private function preGraphCreation() { // Initialize the graph $this->objChart = new pChart($this->intWidth, $this->intHeight); //set the color palette to be used foreach ($this->arrDefaultColorPalette as $intKey => $strCurrentColor) { $arrCurColor = hex2rgb($strCurrentColor); $this->objChart->setColorPalette($intKey, $arrCurColor[0], $arrCurColor[1], $arrCurColor[2]); } //calculate all needed params, draw that funky shit //the outer bounding and pane - rounded and with sharp corners $arrBackgroundColor = hex2rgb($this->strBackgroundColor); if ($this->bitRoundedCorners) { $this->objChart->drawFilledRoundedRectangle(2, 2, $this->intWidth - 3, $this->intHeight - 3, 5, $arrBackgroundColor[0], $arrBackgroundColor[1], $arrBackgroundColor[2]); $arrOuterBack = hex2rgb($this->strOuterFrameColor); $this->objChart->drawRoundedRectangle(0, 0, $this->intWidth - 1, $this->intHeight - 1, 5, $arrOuterBack[0], $arrOuterBack[1], $arrOuterBack[2]); } else { $this->objChart->drawFilledRectangle(0, 0, $this->intWidth, $this->intHeight, $arrBackgroundColor[0], $arrBackgroundColor[1], $arrBackgroundColor[2]); } //the graph area - x and or y-axis label present? if ($this->bitRenderLegend) { $intRightMargin = 10; } else { $intRightMargin = 20; } $intTopMargin = 15; $intBottomMargin = 30; $intLeftMargin = 40; $intLegendWidth = 0; if ($this->bitRenderLegend) { $intLegendWidth = 120; } $intWidth = $this->intWidth - $intRightMargin - $intLegendWidth; $intHeight = $this->intHeight - $intBottomMargin; $intLeftStart = $intLeftMargin; $intTopStart = $intTopMargin; if ($this->strYAxisTitle != "") { $intLeftStart += 15; //$intWidth -= 15; //TODO: why not needed? } if ($this->strXAxisTitle != "") { $intHeight -= 15; } if ($this->strGraphTitle != "") { //$intHeight -= 12; //TODO: why not needed??? $intTopStart += 12; } if ($this->intCurrentGraphMode != $this->GRAPH_TYPE_PIE) { $this->objChart->setGraphArea($intLeftStart, $intTopStart, $intWidth, $intHeight); $arrPaneBackground = hex2rgb($this->strGraphBackgroundColor); $this->objChart->drawGraphArea($arrPaneBackground[0], $arrPaneBackground[1], $arrPaneBackground[2], true); } $arrFontColors = hex2rgb($this->strFontColor); $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 8); //set up the axis-titles if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_BAR || $this->intCurrentGraphMode == $this->GRAPH_TYPE_STACKEDBAR || $this->intCurrentGraphMode == $this->GRAPH_TYPE_LINE) { if ($this->strXAxisTitle != "") { $this->objDataset->SetXAxisName($this->strXAxisTitle); } if ($this->strYAxisTitle != "") { $this->objDataset->SetYAxisName($this->strYAxisTitle); } } //the x- and y axis, in- / exclusive margins if ($this->bitAdditionalDatasetAdded && $this->bitScaleFromAdditionalDataset) { $this->objChart->drawScale($this->objAdditionalDataset->GetData(), $this->objAdditionalDataset->GetDataDescription(), SCALE_START0, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, true); } else { if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_BAR) { $this->objChart->drawScale($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), SCALE_START0, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, true); } else { if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_STACKEDBAR) { $this->objChart->drawScale($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), SCALE_ADDALLSTART0, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, true); } else { if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_LINE) { $this->objChart->drawScale($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), SCALE_NORMAL, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, false); } } } } //the background grid if ($this->intCurrentGraphMode != $this->GRAPH_TYPE_PIE) { $arrGridColor = hex2rgb($this->strGridColor); $this->objChart->drawGrid(4, true, $arrGridColor[0], $arrGridColor[1], $arrGridColor[2], 50); } if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_LINE) { // Draw the line graph $this->objChart->drawLineGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription()); //dots in line $this->objChart->drawPlotGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), 3, 2, 255, 255, 255); } else { if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_BAR) { //the zero-line $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 6); $this->objChart->drawBarGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), TRUE); $this->objChart->drawTreshold(0, 143, 55, 72, TRUE, TRUE); //if given, render the line-plots on top if ($this->bitAdditionalDatasetAdded) { //the line itself $this->objChart->drawLineGraph($this->objAdditionalDataset->GetData(), $this->objAdditionalDataset->GetDataDescription()); //the dots $this->objChart->drawPlotGraph($this->objAdditionalDataset->GetData(), $this->objAdditionalDataset->GetDataDescription(), 3, 2, 255, 255, 255); } } else { if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_STACKEDBAR) { //the zero-line $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 6); $this->objChart->drawTreshold(0, 143, 55, 72, TRUE, TRUE); $this->objChart->drawStackedBarGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), 75); } else { if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_PIE) { $this->objChart->drawPieGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), ceil($this->intWidth / 2) - 20, ceil($this->intHeight / 2), ceil($intHeight / 2) + 20, PIE_PERCENTAGE, TRUE, 50, 20, 5); } } } } //render values? if (count($this->arrValueSeriesToRender) > 0) { $this->objChart->writeValues($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), $this->arrValueSeriesToRender); } // Finish the graph $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 7); //set up the legend if ($this->bitRenderLegend) { if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_PIE) { $this->objChart->drawPieLegend($this->intWidth - $intLegendWidth - $intRightMargin + 10 - $this->intLegendAdditionalMargin, $intTopStart, $this->objDataset->GetData(), $this->objDataset->GetDataDescription(), 255, 255, 255); } else { $arrLegend = $this->objDataset->GetDataDescription(); //merge legends if ($this->bitAdditionalDatasetAdded) { $arrAdditionalLegend = $this->objAdditionalDataset->GetDataDescription(); foreach ($arrAdditionalLegend["Description"] as $strKey => $strName) { $arrLegend["Description"][$strKey] = $strName; } } $this->objChart->drawLegend($this->intWidth - $intLegendWidth - $intRightMargin + 10 - $this->intLegendAdditionalMargin, $intTopStart, $arrLegend, 255, 255, 255); } } //draw the title if ($this->strGraphTitle != "") { $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 10); $this->objChart->drawTitle(0, $intTopMargin, $this->strGraphTitle, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], $this->intWidth, 10); } }
function showGraph($searchInfo = '') { $conditions = empty($searchInfo['keywordId']) ? "" : " and s.keyword_id=" . intval($searchInfo['keywordId']); $conditions .= empty($searchInfo['seId']) ? "" : " and s.searchengine_id=" . intval($searchInfo['seId']); $sql = "select s.*,se.domain \r\n\t\t\t\t\tfrom searchresults s,searchengines se \r\n\t\t\t\t\twhere s.searchengine_id=se.id \r\n\t\t\t\t\tand time>= " . intval($searchInfo['fromTime']) . " and time<" . intval($searchInfo['toTime']) . " {$conditions} \r\n\t\t\t\t\torder by s.time"; $repList = $this->db->select($sql); $reportList = array(); $seList = array(); foreach ($repList as $repInfo) { $var = $repInfo['searchengine_id'] . $repInfo['keyword_id'] . $repInfo['time']; if (empty($reportList[$var])) { $reportList[$var] = $repInfo; } else { if ($repInfo['rank'] < $reportList[$var]['rank']) { $reportList[$var] = $repInfo; } } if (empty($seList[$repInfo['searchengine_id']])) { $seList[$repInfo['searchengine_id']] = $repInfo['domain']; } } asort($seList); $dataList = array(); $maxValue = 0; foreach ($reportList as $repInfo) { $seId = $repInfo['searchengine_id']; $dataList[$repInfo['time']][$seId] = $repInfo['rank']; $maxValue = $repInfo['rank'] > $maxValue ? $repInfo['rank'] : $maxValue; } // check whether the records are available for drawing graph if (empty($dataList) || empty($maxValue)) { $kpText = $_SESSION['lang_code'] == 'ja' ? $_SESSION['text']['common']['No Records Found'] . "!" : "No Records Found!"; $this->showMessageAsImage($kpText); } # Dataset definition $dataSet = new pData(); foreach ($dataList as $dataInfo) { $i = 1; foreach ($seList as $seId => $seVal) { $val = empty($dataInfo[$seId]) ? 0 : $dataInfo[$seId]; $dataSet->AddPoint($val, "Serie" . $i++); } } $i = 1; foreach ($seList as $seDomain) { $dataSet->AddSerie("Serie{$i}"); $dataSet->SetSerieName($seDomain, "Serie{$i}"); $i++; } $serieCount = count($seList) + 1; $dataSet->AddPoint(array_keys($dataList), "Serie{$serieCount}"); $dataSet->SetAbsciseLabelSerie("Serie{$serieCount}"); # if language is japanese if ($_SESSION['lang_code'] == 'ja') { $fontFile = "fonts/M+1P+IPAG.ttf"; $dataSet->SetXAxisName($_SESSION['text']['common']["Date"]); $dataSet->SetYAxisName($_SESSION['text']['common']["Rank"]); } else { $fontFile = "fonts/tahoma.ttf"; $dataSet->SetXAxisName("Date"); $dataSet->SetYAxisName("Rank"); } $dataSet->SetXAxisFormat("date"); # Initialise the graph $chart = new pChart(720, 520); $chart->setFixedScale($maxValue, 1); $chart->setFontProperties($fontFile, 8); $chart->setGraphArea(85, 30, 670, 425); $chart->drawFilledRoundedRectangle(7, 7, 713, 513, 5, 240, 240, 240); $chart->drawRoundedRectangle(5, 5, 715, 515, 5, 230, 230, 230); $chart->drawGraphArea(255, 255, 255, TRUE); $chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 90, 2); $chart->drawGrid(4, TRUE, 230, 230, 230, 50); # Draw the 0 line $chart->setFontProperties($fontFile, 6); $chart->drawTreshold(0, 143, 55, 72, TRUE, TRUE); # Draw the line graph $chart->drawLineGraph($dataSet->GetData(), $dataSet->GetDataDescription()); $chart->drawPlotGraph($dataSet->GetData(), $dataSet->GetDataDescription(), 3, 2, 255, 255, 255); $j = 1; $chart->setFontProperties($fontFile, 10); foreach ($seList as $seDomain) { $chart->writeValues($dataSet->GetData(), $dataSet->GetDataDescription(), "Serie" . $j++); } # Finish the graph $chart->setFontProperties("fonts/tahoma.ttf", 8); $chart->drawLegend(90, 35, $dataSet->GetDataDescription(), 255, 255, 255); $chart->setFontProperties($fontFile, 10); $kpText = $_SESSION['lang_code'] == 'ja' ? $this->spTextKeyword["Keyword Position Report"] : "Keyword Position Report"; $chart->drawTitle(60, 22, $kpText, 50, 50, 50, 585); $chart->stroke(); }
function showGraph($searchInfo = '') { $conditions = empty($searchInfo['keywordId']) ? "" : " and s.keyword_id=" . $searchInfo['keywordId']; $conditions .= empty($searchInfo['seId']) ? "" : " and s.searchengine_id=" . $searchInfo['seId']; $sql = "select s.*,se.domain \r\n\t\t\t\t\tfrom searchresults s,searchengines se \r\n\t\t\t\t\twhere s.searchengine_id=se.id \r\n\t\t\t\t\tand time>= {$searchInfo['fromTime']} and time<{$searchInfo['toTime']} {$conditions} \r\n\t\t\t\t\torder by s.time"; $repList = $this->db->select($sql); $reportList = array(); $seList = array(); foreach ($repList as $repInfo) { $var = $repInfo['searchengine_id'] . $repInfo['keyword_id'] . $repInfo['time']; if (empty($reportList[$var])) { $reportList[$var] = $repInfo; } else { if ($repInfo['rank'] < $reportList[$var]['rank']) { $reportList[$var] = $repInfo; } } if (empty($seList[$repInfo['searchengine_id']])) { $seList[$repInfo['searchengine_id']] = $repInfo['domain']; } } asort($seList); $dataList = array(); foreach ($reportList as $repInfo) { $seId = $repInfo['searchengine_id']; $dataList[$repInfo['time']][$seId] = $repInfo['rank']; } # Dataset definition $dataSet = new pData(); foreach ($dataList as $dataInfo) { $i = 1; foreach ($seList as $seId => $seVal) { $val = empty($dataInfo[$seId]) ? 0 : $dataInfo[$seId]; $dataSet->AddPoint($val, "Serie" . $i++); } } $i = 1; foreach ($seList as $seDomain) { $dataSet->AddSerie("Serie{$i}"); $dataSet->SetSerieName($seDomain, "Serie{$i}"); $i++; } $serieCount = count($seList) + 1; $dataSet->AddPoint(array_keys($dataList), "Serie{$serieCount}"); $dataSet->SetAbsciseLabelSerie("Serie{$serieCount}"); $dataSet->SetXAxisName("Date"); $dataSet->SetYAxisName("Rank"); $dataSet->SetXAxisFormat("date"); # Initialise the graph $chart = new pChart(720, 520); $chart->setFontProperties("fonts/tahoma.ttf", 8); $chart->setGraphArea(85, 30, 670, 425); $chart->drawFilledRoundedRectangle(7, 7, 713, 513, 5, 240, 240, 240); $chart->drawRoundedRectangle(5, 5, 715, 515, 5, 230, 230, 230); $chart->drawGraphArea(255, 255, 255, TRUE); $chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 90, 2); $chart->drawGrid(4, TRUE, 230, 230, 230, 50); # Draw the 0 line $chart->setFontProperties("fonts/tahoma.ttf", 6); $chart->drawTreshold(0, 143, 55, 72, TRUE, TRUE); # Draw the line graph $chart->drawLineGraph($dataSet->GetData(), $dataSet->GetDataDescription()); $chart->drawPlotGraph($dataSet->GetData(), $dataSet->GetDataDescription(), 3, 2, 255, 255, 255); $j = 1; $chart->setFontProperties("fonts/tahoma.ttf", 10); foreach ($seList as $seDomain) { $chart->writeValues($dataSet->GetData(), $dataSet->GetDataDescription(), "Serie" . $j++); } # Finish the graph $chart->setFontProperties("fonts/tahoma.ttf", 8); $chart->drawLegend(90, 35, $dataSet->GetDataDescription(), 255, 255, 255); $chart->setFontProperties("fonts/tahoma.ttf", 10); $chart->drawTitle(60, 22, "Keyword Position Report", 50, 50, 50, 585); $chart->stroke(); }
// 设置作图区域 $pChartGraph = new pChart($imgWidth, 253); $pChartGraph->drawGraphAreaGradient(90, 90, 90, 90, TARGET_BACKGROUND); $pChartGraph->setGraphArea(70, 30, $imgWidth + 70 - 90, 253 + 30 - 80); $pChartGraph->setFontProperties(DRAWFONE_PATH, 8); $pChartGraph->drawScale($pChartDataSet->GetData(), $pChartDataSet->GetDataDescription(), SCALE_NORMAL, 250, 250, 250, TRUE, 0, 0, FALSE, 1); // 开始作图 $pChartGraph->setColorPalette(0, 0, 255, 255); $pChartGraph->drawGraphAreaGradient(40, 40, 40, -50); $pChartGraph->drawGrid(1, TRUE, 115, 115, 115, 10); $pChartGraph->setShadowProperties(3, 3, 0, 0, 0, 30, 4); $pChartGraph->drawFilledLineGraph($pChartDataSet->GetData(), $pChartDataSet->GetDataDescription(), 25); $pChartGraph->clearShadow(); $pChartGraph->setFontProperties(DRAWFONE_PATH, 10); $pChartGraph->drawTitle($imgWidth / 2, 22, "实时在线人数查询(" . $dateTime . ") 峰值( " . $maxNumberIndex . ", " . $maxNumber . "人 )", 255, 255, 255, 585); $pChartGraph->writeValues($pChartDataSet->GetData(), $pChartDataSet->GetDataDescription(), "Serie2"); // 结束 $pChartGraph->Stroke(); // $pChartGraph->Render("RealTimeOnLine.png"); // echo "<img src = 'RealTimeOnLine.png'>"; // $fileNameTxt = "Cache/XYInfo.".$plat.$server.$dateTime.".txt"; // $file = fopen($fileNameTxt,"w"); // $info = $pChartGraph->DivisionWidth.",".$pChartGraph->GArea_Y2.",".$pChartGraph->VMin.",".$pChartGraph->DivisionRatio; // fwrite($file,$info); // fclose($file); ?>
public function gerarGraficoLinhas() { if (count($this->_dados[0]) < 1) { die("Algum dado deve ser passado. <br>Ex. \$grafico->setDados(array(10,20,30));"); } if (count($this->_dados[0]) != count($this->_tituloItens)) { die("A quantidade de titulos passados difere da quantidade de valores. Certifique-se de que eles estejam em igual numero."); } // Montando plotagens com os arrays de dados passados $DataSet = new pData(); // Definindo labels dos eixos if (!empty($this->_tituloEixoX)) { $DataSet->SetXAxisName($this->_tituloEixoX); $DataSet->SetYAxisName($this->_tituloEixoY); } // Montando plotagens com os arrays de dados passados for ($i = 0; $i < count($this->_dados); $i++) { $DataSet->AddPoint($this->_dados[$i], $this->_tituloDados[$i]); $DataSet->AddSerie($this->_tituloDados[$i]); //x($this->_tituloItens[$i]); } // Definindo labels dos dados if (count($this->_tituloItens) > 0) { $DataSet->AddPoint($this->_tituloItens, "labels"); $DataSet->SetAbsciseLabelSerie("labels"); } // Initialise the graph $Test = new pChart($this->_larguraGrafico * 2, $this->_alturaGrafico * 2); $Test->setFontProperties(CAMINHO_PCHART_FONT . "/tahoma.ttf", 8); $Test->setGraphArea($this->_margem * 3, $this->_margem * 2, 120 * $this->_larguraGrafico / 100, 130 * $this->_alturaGrafico / 100 - 10); $Test->drawFilledRoundedRectangle(7, 7, 150 * $this->_larguraGrafico / 100, 150 * $this->_alturaGrafico / 100, 5, $this->_corFundo["r"], $this->_corFundo["g"], $this->_corFundo["b"]); $Test->drawRoundedRectangle(5, 5, 150 * $this->_larguraGrafico / 100 + 3, 150 * $this->_alturaGrafico / 100 + 3, 5, $this->_corMargem["r"], $this->_corMargem["g"], $this->_corMargem["b"]); $Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, $this->_corLabels["r"], $this->_corLabels["g"], $this->_corLabels["b"], TRUE, $this->_anguloValores, 0, TRUE); $Test->drawGrid(4, TRUE); // Draw the 0 line $Test->setFontProperties(CAMINHO_PCHART_FONT . "/tahoma.ttf", 10); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); if ($this->_qtdeSeries <= 1 && $this->_exibirValores == true) { $Test->writeValues($DataSet->GetData(), $DataSet->GetDataDescription(), $this->_tituloDados); } // Draw the limit graph $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); // Finish the graph $Test->setFontProperties(CAMINHO_PCHART_FONT . "/tahoma.ttf", 8); $Test->drawLegend(72 * $this->_larguraGrafico / 100, 50, $DataSet->GetDataDescription(), 255, 249, 223, 15, 15, 15); $Test->setFontProperties(CAMINHO_PCHART_FONT . "/tahoma.ttf", 14); $Test->drawTitle($this->_larguraGrafico / 2 - 20, 30, $this->_tituloGrafico, $this->_corLabels["r"], $this->_corLabels["g"], $this->_corLabels["b"]); $Test->Stroke(); }
/** * Build The Bar Gharph image with given params * and store in upload/pChart directory. * * @param array $params an assoc array of name/value pairs * @return array $filesPath created image files Path. * * @static */ static function barGraph($params, $divisionWidth = 44) { if (empty($params)) { return; } //get the required directory path. $config =& CRM_Core_Config::singleton(); //get the default currency. $currency = $config->defaultCurrency; $pChartPath = str_replace('templates', 'packages', $config->templateDir); $pChartPath .= 'pChart/Fonts/'; $uploadDirURL = str_replace('persist/contribute/', 'upload/pChart/', $config->imageUploadURL); $uploadDirPath = $config->uploadDir . 'pChart/'; //create pchart directory, if exist clean and then create again. if (is_dir($uploadDirPath)) { CRM_Utils_File::cleanDir($uploadDirPath); CRM_Utils_File::createDir($uploadDirPath); } else { CRM_Utils_File::createDir($uploadDirPath); } require_once 'packages/pChart/pData.class.php'; require_once 'packages/pChart/pChart.class.php'; $chartCount = 0; $filesValues = array(); foreach ($params as $chartIndex => $chartValues) { $chartCount++; $shades = 0; $names = $values = array(); foreach ($chartValues['values'] as $indexName => $indexValue) { $names[] = $indexName; $values[] = $indexValue; $shades++; } $legend = CRM_Utils_Array::value('legend', $chartValues); $xname = CRM_Utils_Array::value('xname', $chartValues); $yname = CRM_Utils_Array::value('yname', $chartValues); //calculate max scale for graph. $maxScale = ceil(max($values) * 1.1); $fontSize = 8; $angleOfIncline = 45; $monetaryformatting = true; require_once 'CRM/Utils/Money.php'; $formatedMoney = CRM_Utils_Money::format(max($values)); $positions = imageftbbox($fontSize, 0, $pChartPath . "tahoma.ttf", $formatedMoney); $scaleTextWidth = $positions[2] - $positions[0]; //need to increase Ysize if we incline money value. $increaseYBy = 0; $inclinePositions = imageftbbox($fontSize, $angleOfIncline, $pChartPath . "tahoma.ttf", $formatedMoney); $inclineTextWidth = $inclinePositions[2] - $inclinePositions[0]; if ($inclineTextWidth > $divisionWidth) { $increaseYBy = $inclineTextWidth / 2; } //Initialise the co-ordinates. $xComponent = 20; $yComponent = 35; $ySize = 300; //calculate coords. $x1 = $xComponent + $scaleTextWidth; $y1 = $yComponent + $increaseYBy; $ySize += $increaseYBy; $y2 = $ySize - $yComponent; //calculate x axis size as per number of months. $x2 = $xComponent + $divisionWidth + $scaleTextWidth + (count($chartValues['values']) - 1) * $divisionWidth; $xSize = $x2 + $xComponent; $dataSet = new pData(); $dataSet->AddPoint($values, "Serie1"); $dataSet->AddPoint($names, "Serie2"); $dataSet->AddSerie("Serie1"); $dataSet->SetAbsciseLabelSerie("Serie2"); //Initialise the graph $chart = new pChart($xSize, $ySize); $chart->setFontProperties($pChartPath . "tahoma.ttf", $fontSize); $chart->setGraphArea($x1, $y1, $x2, $y2); //set the y axis scale. $chart->setFixedScale(0, $maxScale, 1); $chart->drawFilledRoundedRectangle(0, 0, $xSize, $ySize, 5, 240, 240, 240); $chart->drawRoundedRectangle(0, 0, $xSize, $ySize, 5, 230, 230, 230); $chart->drawGraphArea(255, 255, 255, TRUE); $chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE, 1, FALSE, $divisionWidth, $monetaryformatting); $chart->drawGrid(4, TRUE, 230, 230, 230, 50); //set colors. $chart->setColorShades($shades, self::$_colors); //Draw the bar chart $chart->drawBarGraph($dataSet->GetData(), $dataSet->GetDataDescription(), TRUE, 80, true); //get the series values and write at top. $chart->setColorPalette(0, 0, 0, 255); $dataDesc = $dataSet->GetDataDescription(); $chart->writeValues($dataSet->GetData(), $dataSet->GetDataDescription(), $dataDesc['Values'], $monetaryformatting, $angleOfIncline); //Write the title if ($legend) { $chart->setFontProperties($pChartPath . "tahoma.ttf", 10); $chart->drawTitle(10, 20, $legend, 50, 50, 50); } if ($xname) { $chart->setFontProperties($pChartPath . "tahoma.ttf", 8); $chart->drawTitle(0, 90, $xname, 2, 0, 2); } if ($yname) { $chart->setFontProperties($pChartPath . "tahoma.ttf", 8); $chart->drawTitle(40, 290, $yname, 2, 0, 20); } $fileName = "pChartByMonth{$chartCount}" . time() . '.png'; $chart->Render($uploadDirPath . $fileName); //get the file path. $filesValues[$chartIndex]['file_name'] = $uploadDirURL . $fileName; //get the co-ordinates $coords = $chart->coordinates(); //format the coordinates to make graph clickable. $position = 0; $chartCoords = array(); foreach ($chartValues['values'] as $name => $value) { $chartCoords[$name] = implode(',', array($coords['xCoords'][$position], $coords['yCoords'][$position], $coords['xCoords'][$position] + $divisionWidth / 2, $y2)); $position++; } $filesValues[$chartIndex]['coords'] = $chartCoords; //free the chart and data objects. unset($chart); unset($dataSet); } return $filesValues; }