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"); }
/** * Draw bar style chart * @return unknown */ protected function drawBar() { // prepare font & series $this->_prepareSerie(); $this->_prepareFont(); // init chart params $outer_w = $this->w - 5; // Outer frame witdh $outer_h = $this->h - 5; // Outer frame heigth $inner_w = $this->w - 7; // Inner frame witdh $inner_h = $this->h - 7; // Inner frame heigth $chart_w = $this->w - 150; // Chart frame witdh $chart_h = $this->h - 40; // Chart frame heigth $title_w = $this->w - 200; // Title width $title_h = 45; // Title height $legend_w = $chart_w + 30; // Legend width $legend_h = 40; // Legend height // chart styles $grid = isset($this->p['grid']) ? $this->p['grid'] : false; // fill chart $this->chart->drawBackground(255, 255, 255); $this->chart->setFontProperties($this->font, 7); // set font and size $this->chart->drawRoundedRectangle(5, 5, $outer_w, $outer_h, 10, 230, 230, 230); // drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B) $this->chart->drawFilledRoundedRectangle(7, 7, $inner_w, $inner_h, 10, 240, 240, 240); // drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B) $this->chart->setGraphArea(90, 40, $chart_w, $chart_h); // setGraphArea($X1,$Y1,$X2,$Y2) $this->chart->drawGraphArea(255, 255, 255, TRUE); // drawGraphArea($R,$G,$B) $this->chart->drawScale($this->data->GetData(), $this->data->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, $this->margin, $this->skip); // drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1,$RightScale=FALSE) $this->data->RemoveSerie('DEFAULT_SCALE'); // clear scale serie for setScale method // draw grid if ($grid) { $this->chart->drawGrid(3, TRUE, 230, 230, 230, 50); // drawGrid($LineWidth,$Mosaic=TRUE,$R=220,$G=220,$B=220,$Alpha=255) } // draw the cubic curve graph $this->chart->drawBarGraph($this->data->GetData(), $this->data->GetDataDescription(), TRUE); // add Title $this->chart->setFontProperties($this->font, 10); $this->chart->drawTitle(40, 0, $this->title, 50, 50, 50, $title_w, $title_h); // drawTitle($XPos,$YPos,$Value,$R,$G,$B,$XPos2=-1,$YPos2=-1,$Shadow=FALSE) // add Legend $this->chart->setFontProperties($this->font, 8); $this->chart->drawLegend($legend_w, $legend_h, $this->data->GetDataDescription(), 255, 255, 255); // drawLegend($description,$R,$G,$B) }
function index() { $this->load->model('charge_model'); $revenue = $this->charge_model->GetRevenueByDay($this->user->Get('client_id')); $data = array(); if ($this->config->item('show_dashboard_chart') !== 'no' and !empty($revenue) and count($revenue) > 1) { $series = array(); foreach ($revenue as $day) { $series[] = $day['revenue']; $series2[] = date("M j", strtotime($day['day'])); } include APPPATH . 'libraries/pchart/pData.class'; include APPPATH . 'libraries/pchart/pChart.class'; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint($series, "Revenue"); $DataSet->AddPoint($series2, "Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Serie2"); $DataSet->RemoveSerie("Serie2"); $DataSet->SetXAxisName('Date'); $DataSet->SetYAxisName('Revenue'); //$DataSet->SetXAxisFormat('date'); // Initialise the graph $Test = new pChart(1000, 260); $Test->setFontProperties(APPPATH . 'libraries/pchart/Arial.ttf', 10); $Test->setGraphArea(90, 30, 960, 200); $Test->drawGraphArea(252, 252, 252); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2); $Test->drawGrid(4, TRUE, 230, 230, 230, 255); // Draw the line graph $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255); // Finish the graph $Test->setFontProperties(APPPATH . 'libraries/pchart/Arial.ttf', 8); $Test->drawLegend(45, 35, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties(APPPATH . 'libraries/pchart/Arial.ttf', 10); //$Test->drawTitle(60,22,"Last 30 Days",50,50,50,585); $Test->Render(BASEPATH . '../writeable/rev_chart_' . $this->user->Get('client_id') . '.png'); } else { $data['no_chart'] = 'true'; } // get log $this->load->model('log_model'); $log = $this->log_model->GetClientLog($this->user->Get('client_id')); $data['log'] = $log; $this->load->view(branded_view('cp/dashboard'), $data); }
function writeBarData($data, $graph) { if ($data != "") { echo "Plottong " . $graph . "\n"; $dataset1 = array(); $dataset2 = array(); $counter = 0; $toggle = true; $data = array_reverse($data, TRUE); ksort($data); foreach ($data as $key => $value) { if ($counter % 5 != 0) { $key = " "; } array_push($dataset1, $key); array_push($dataset2, $value); $counter++; } // Dataset definition $DataSet = new pData(); $DataSet->AddPoint($dataset2, "Serie1"); $DataSet->AddPoint($dataset1, "XLabel"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("XLabel"); $DataSet->RemoveSerie("XLabel"); $DataSet->SetSerieName("Membership", "Serie1"); // Initialise the graph $Test = new pChart(700, 230); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(50, 30, 680, 200); $Test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 695, 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); // Draw the 0 line $Test->setFontProperties("Fonts/tahoma.ttf", 6); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the bar graph $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE); // Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->drawLegend(596, 150, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Test->drawTitle(50, 22, "Membership by Month", 50, 50, 50, 585); $Test->Render("{$graph}-bar.png"); } }
function generate_image($site_name, $visits) { $font = APP_PATH . "libs/pchart/Fonts/tahoma.ttf"; //$font = APP_PATH."includes/pchart/Fonts/DejaVuSans.ttf"; global $lang; // Dataset definition $DataSet = new pData(); $names = array(); $points = array(); foreach ($visits as $date => $visit) { $points[] = $visit; $text = $lang['days'][date('N', strtotime($date))]; $names[] = $text; } $DataSet->AddPoint($points, "Lankytojai"); $DataSet->AddPoint($names, "days"); $DataSet->AddAllSeries(); $DataSet->RemoveSerie("days"); $DataSet->SetAbsciseLabelSerie('days'); // Initialise the graph $Test = new pChart(700, 230); $Test->setFontProperties($font, 8); $Test->setGraphArea(50, 30, 680, 200); $Test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 695, 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); // Draw the 0 line $Test->setFontProperties($font, 6); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the bar graph $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE, 80); // Finish the graph $Test->setFontProperties($font, 8); // $Test->drawLegend(100,20,$DataSet->GetDataDescription(),255,255,255); $Test->drawLegend(610, 10, $DataSet->GetDataDescription(), 236, 238, 240, 52, 58, 82); $Test->setFontProperties($font, 10); $Test->drawTitle(50, 22, $site_name, 50, 50, 50, 585); $path = IMAGE_PATH . "{$site_name}.png"; if (file_exists($path)) { unlink($path); } $Test->Render($path); return $path; }
$DataSet->SetYAxisName("Response time"); $DataSet->SetXAxisName("Sample #ID"); //print_r($DataSet->GetData()); // Initialise the graph $Test = new pChart(700, 230); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(55, 30, 585, 185); $Test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 695, 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); // Draw the 0 line $Test->setFontProperties("Fonts/tahoma.ttf", 6); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the line graph $DataSet->RemoveSerie("Serie2"); $Test->drawFilledLineGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 60, TRUE); // Draw the curve graph $DataSet->RemoveSerie("Serie1"); $DataSet->AddSerie("Serie2"); $Test->setShadowProperties(2, 2, 200, 200, 200, 50); $Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255); $Test->clearShadow(); // Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->drawLegend(600, 30, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Test->drawTitle(50, 22, "Example 18", 50, 50, 50, 585); $Test->Render("example18.png");
function createChart(&$info, &$cfg) { $backgndColor = array('R' => 255, 'G' => 255, 'B' => 254); $chartCfg = new stdClass(); $chartCfg->XSize = $info->canDraw ? $cfg->XSize : 600; $chartCfg->YSize = $info->canDraw ? $cfg->YSize : 50; $chartCfg->border = new stdClass(); $chartCfg->border->width = 1; $chartCfg->border->color = array('R' => 0, 'G' => 0, 'B' => 0); $chartCfg->graphArea = new stdClass(); $chartCfg->graphArea->color = array('R' => 213, 'G' => 217, 'B' => 221); $chartCfg->graphArea->beginX = 40; $chartCfg->graphArea->beginY = 40; $chartCfg->graphArea->endX = $chartCfg->XSize - $chartCfg->graphArea->beginX; $chartCfg->graphArea->endY = $chartCfg->YSize - $chartCfg->graphArea->beginY; $chartCfg->scale = new stdClass(); $chartCfg->scale->mode = SCALE_ADDALL; $chartCfg->scale->color = array('R' => 0, 'G' => 0, 'B' => 0); $chartCfg->scale->drawTicks = TRUE; $chartCfg->scale->angle = $cfg->scale->legendXAngle; $chartCfg->scale->decimals = 1; $chartCfg->scale->withMargin = TRUE; $chartCfg->legend = new stdClass(); $chartCfg->legend->X = $chartCfg->XSize - 80; $chartCfg->legend->Y = 15; $chartCfg->legend->color = array('R' => 236, 'G' => 238, 'B' => 240); $chartCfg->title = new stdClass(); $chartCfg->title->value = $cfg->chartTitle; $chartCfg->title->X = 2 * $chartCfg->graphArea->beginX; $chartCfg->title->Y = $chartCfg->legend->Y; $chartCfg->title->color = array('R' => 0, 'G' => 0, 'B' => 255); $Test = new pChart($chartCfg->XSize, $chartCfg->YSize); $Test->drawBackground($backgndColor['R'], $backgndColor['G'], $backgndColor['B']); $Test->drawGraphArea($chartCfg->graphArea->color['R'], $chartCfg->graphArea->color['G'], $chartCfg->graphArea->color['B']); $Test->setGraphArea($chartCfg->graphArea->beginX, $chartCfg->graphArea->beginY, $chartCfg->graphArea->endX, $chartCfg->graphArea->endY); $Test->setFontProperties(config_get('charts_font_path'), config_get('charts_font_size')); if ($info->canDraw) { $DataSet = new pData(); foreach ($info->chart_data as $key => $values) { $id = $key + 1; $DataSet->AddPoint($values, "Serie{$id}"); $DataSet->SetSerieName($info->series_label[$key], "Serie{$id}"); } $DataSet->AddPoint($info->xAxis->values, $info->xAxis->serieName); $DataSet->AddAllSeries(); $DataSet->RemoveSerie($info->xAxis->serieName); $DataSet->SetAbsciseLabelSerie($info->xAxis->serieName); $chartData = $DataSet->GetData(); $chartLegend = $DataSet->GetDataDescription(); foreach ($info->series_color as $key => $hexrgb) { $rgb = str_split($hexrgb, 2); $Test->setColorPalette($key, hexdec($rgb[0]), hexdec($rgb[1]), hexdec($rgb[2])); } // $Test->setFixedScale($info->scale->minY,$info->scale->maxY,$info->scale->divisions); $Test->drawScale($chartData, $chartLegend, $chartCfg->scale->mode, $chartCfg->scale->color['R'], $chartCfg->scale->color['G'], $chartCfg->scale->color['B'], $chartCfg->scale->drawTicks, $chartCfg->scale->angle, $chartCfg->scale->decimals, $chartCfg->scale->withMargin); $Test->drawStackedBarGraph($chartData, $chartLegend, 70); // Draw the legend $Test->setFontProperties(config_get('charts_font_path'), config_get('charts_font_size')); $Test->drawLegend($chartCfg->legend->X, $chartCfg->legend->Y, $chartLegend, $chartCfg->legend->color['R'], $chartCfg->legend->color['G'], $chartCfg->legend->color['B']); $Test->addBorder($chartCfg->border->width, $chartCfg->border->color['R'], $chartCfg->border->color['G'], $chartCfg->border->color['B']); } else { $chartCfg->title->value .= '/' . lang_get('no_data_available'); } $Test->drawTitle($chartCfg->title->X, $chartCfg->title->Y, $chartCfg->title->value, $chartCfg->title->color['R'], $chartCfg->title->color['G'], $chartCfg->title->color['B']); $Test->Stroke(); }
/** * This function draw the graphic to be displayed on the user view as an image * * @param array $sql_result * @param string $start_date * @param string $end_date * @param string $type * @author Jorge Frisancho Jibaja * @version OCT-22- 2010 * @return string */ function grapher($sql_result, $start_date, $end_date, $type = "") { require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php'; require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php'; require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php'; if (empty($start_date)) { $start_date =""; } if (empty($end_date)) { $end_date =""; } if ($type == ""){ $type = 'day'; } $main_year = $main_month_year = $main_day = array(); // get last 8 days/months $last_days = 5; $last_months = 3; for ($i = $last_days; $i >= 0; $i--) { $main_day[date ('d-m-Y', mktime () - $i * 3600 * 24)] = 0; } for ($i = $last_months; $i >= 0; $i--) { $main_month_year[date ('m-Y', mktime () - $i * 30 * 3600 * 24)] = 0; } $i = 0; if (is_array($sql_result) && count($sql_result) > 0) { foreach ($sql_result as $key => $data) { //creating the main array $main_month_year[date('m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0); $main_day[date('d-m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0); if ($i > 500) { break; } $i++; } switch ($type) { case 'day': $main_date = $main_day; break; case 'month': $main_date = $main_month_year; break; case 'year': $main_date = $main_year; break; } // the nice graphics :D $labels = array_keys($main_date); if (count($main_date) == 1) { $labels = $labels[0]; $main_date = $main_date[$labels]; } $data_set = new pData(); $data_set->AddPoint($main_date, 'Q'); if (count($main_date)!= 1) { $data_set->AddPoint($labels, 'Date'); } $data_set->AddAllSeries(); $data_set->RemoveSerie('Date'); $data_set->SetAbsciseLabelSerie('Date'); $data_set->SetYAxisName(get_lang('Minutes', '')); $graph_id = api_get_user_id().'AccessDetails'.api_get_course_id().$start_date.$end_date.$type; $data_set->AddAllSeries(); $cache = new pCache(); // the graph id $data = $data_set->GetData(); if ($cache->IsInCache($graph_id, $data_set->GetData())) { //if (0) { //if we already created the img // echo 'in cache'; $img_file = $cache->GetHash($graph_id, $data_set->GetData()); } else { // if the image does not exist in the archive/ folder // Initialise the graph $test = new pChart(760, 230); //which schema of color will be used $quant_resources = count($data[0]) - 1; // Adding the color schemma $test->loadColorPalette(api_get_path(LIBRARY_PATH).'pchart/palette/default.txt'); $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 8); $test->setGraphArea(70, 30, 680, 200); $test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240); $test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230); $test->drawGraphArea(255, 255, 255, TRUE); $test->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 0, 0); $test->drawGrid(4, TRUE, 230, 230, 230, 50); $test->setLineStyle(2); // Draw the 0 line $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 6); $test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); if (count($main_date) == 1) { //Draw a graph echo '<strong>'.$labels.'</strong><br/>'; $test->drawBarGraph($data_set->GetData(), $data_set->GetDataDescription(), TRUE); } else { //Draw the line graph $test->drawLineGraph($data_set->GetData(), $data_set->GetDataDescription()); $test->drawPlotGraph($data_set->GetData(), $data_set->GetDataDescription(), 3, 2, 255, 255, 255); } // Finish the graph $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 8); $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 10); $test->drawTitle(60, 22, get_lang('AccessDetails'), 50, 50, 50, 585); //------------------ //echo 'not in cache'; $cache->WriteToCache($graph_id, $data_set->GetData(), $test); ob_start(); $test->Stroke(); ob_end_clean(); $img_file = $cache->GetHash($graph_id, $data_set->GetData()); } $foo_img = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">'; return $foo_img; } else { $foo_img = api_convert_encoding('<div id="messages" class="warning-message">'.get_lang('GraphicNotAvailable').'</div>','UTF-8'); return $foo_img; } }
function createChart(&$info, &$cfg) { $backgndColor = array('R' => 255, 'G' => 255, 'B' => 254); $chartCfg = new stdClass(); $chartCfg->XSize = $info->canDraw ? $cfg->XSize : 600; $chartCfg->YSize = $info->canDraw ? $cfg->YSize : 50; $chartCfg->border = new stdClass(); $chartCfg->border->width = 1; $chartCfg->border->color = array('R' => 0, 'G' => 0, 'B' => 0); $chartCfg->graphArea = new stdClass(); $chartCfg->graphArea->color = array('R' => 213, 'G' => 217, 'B' => 221); $chartCfg->graphArea->beginX = property_exists($cfg, 'beginX') ? $cfg->beginX : 40; $chartCfg->graphArea->beginY = property_exists($cfg, 'beginY') ? $cfg->beginY : 100; $chartCfg->graphArea->endX = $chartCfg->XSize - $chartCfg->graphArea->beginX; $chartCfg->graphArea->endY = $chartCfg->YSize - $chartCfg->graphArea->beginY; $chartCfg->scale = new stdClass(); // 20100914 - franciscom // After reading documentation // drawScale // Today there is four way of computing scales : // // - Getting Max & Min values per serie : ScaleMode = SCALE_NORMAL // - Like the previous one but setting the min value to 0 : ScaleMode = SCALE_START0 // - Getting the series cumulative Max & Min values : ScaleMode = SCALE_ADDALL // - Like the previous one but setting the min value to 0 : ScaleMode = SCALE_ADDALLSTART0 // // This will depends on the kind of graph you are drawing, today only the stacked bar chart // can use the SCALE_ADDALL mode. // Drawing graphs were you want to fix the min value to 0 you must use the SCALE_START0 option. // $chartCfg->scale->mode = SCALE_ADDALLSTART0; $chartCfg->scale->color = array('R' => 0, 'G' => 0, 'B' => 0); $chartCfg->scale->drawTicks = TRUE; $chartCfg->scale->angle = $cfg->scale->legendXAngle; $chartCfg->scale->decimals = 1; $chartCfg->scale->withMargin = TRUE; $chartCfg->legend = new stdClass(); $chartCfg->legend->X = $chartCfg->XSize - 80; $chartCfg->legend->Y = 15; $chartCfg->legend->color = array('R' => 236, 'G' => 238, 'B' => 240); $chartCfg->title = new stdClass(); $chartCfg->title->value = $cfg->chartTitle; $chartCfg->title->X = 2 * $chartCfg->graphArea->beginX; $chartCfg->title->Y = $chartCfg->legend->Y; $chartCfg->title->color = array('R' => 0, 'G' => 0, 'B' => 255); $Test = new pChart($chartCfg->XSize, $chartCfg->YSize); $Test->reportWarnings("GD"); $Test->drawBackground($backgndColor['R'], $backgndColor['G'], $backgndColor['B']); $Test->drawGraphArea($chartCfg->graphArea->color['R'], $chartCfg->graphArea->color['G'], $chartCfg->graphArea->color['B']); $Test->setGraphArea($chartCfg->graphArea->beginX, $chartCfg->graphArea->beginY, $chartCfg->graphArea->endX, $chartCfg->graphArea->endY); $Test->setFontProperties(config_get('charts_font_path'), config_get('charts_font_size')); if ($info->canDraw) { $DataSet = new pData(); foreach ($info->chart_data as $key => $values) { $id = $key + 1; $DataSet->AddPoint($values, "Serie{$id}"); $DataSet->SetSerieName($info->series_label[$key], "Serie{$id}"); } $DataSet->AddPoint($info->xAxis->values, $info->xAxis->serieName); $DataSet->AddAllSeries(); $DataSet->RemoveSerie($info->xAxis->serieName); $DataSet->SetAbsciseLabelSerie($info->xAxis->serieName); $chartData = $DataSet->GetData(); $chartLegend = $DataSet->GetDataDescription(); foreach ($info->series_color as $key => $hexrgb) { $rgb = str_split($hexrgb, 2); $Test->setColorPalette($key, hexdec($rgb[0]), hexdec($rgb[1]), hexdec($rgb[2])); } // $Test->setFixedScale($info->scale->minY,$info->scale->maxY,$info->scale->divisions); $Test->drawScale($chartData, $chartLegend, $chartCfg->scale->mode, $chartCfg->scale->color['R'], $chartCfg->scale->color['G'], $chartCfg->scale->color['B'], $chartCfg->scale->drawTicks, $chartCfg->scale->angle, $chartCfg->scale->decimals, $chartCfg->scale->withMargin); $Test->drawStackedBarGraph($chartData, $chartLegend, 70); // Draw the legend $Test->setFontProperties(config_get('charts_font_path'), config_get('charts_font_size')); $Test->drawLegend($chartCfg->legend->X, $chartCfg->legend->Y, $chartLegend, $chartCfg->legend->color['R'], $chartCfg->legend->color['G'], $chartCfg->legend->color['B']); $Test->addBorder($chartCfg->border->width, $chartCfg->border->color['R'], $chartCfg->border->color['G'], $chartCfg->border->color['B']); } else { $chartCfg->title->value .= '/' . lang_get('no_data_available'); } $Test->drawTitle($chartCfg->title->X, $chartCfg->title->Y, $chartCfg->title->value, $chartCfg->title->color['R'], $chartCfg->title->color['G'], $chartCfg->title->color['B']); $Test->Stroke(); }
public function build() { require_once PCHART_BASE_DIR . DIRECTORY_SEPARATOR . 'pData.php'; require_once PCHART_BASE_DIR . DIRECTORY_SEPARATOR . 'pChart.php'; $dataSet = new pData(); foreach ($this->lines as $name => $ordinateValues) { if (count($ordinateValues) != count($this->absciseValues)) { throw new Exception('Count of line "' . $name . '" ordinate points "' . count($ordinateValues) . '" mismatch to abscise points "' . count($this->absciseValues) . '"'); } $dataSet->AddPoint($ordinateValues, $name); } $dataSet->AddPoint($this->absciseValues, 'Abscise'); $dataSet->AddAllSeries(); $dataSet->RemoveSerie('Abscise'); $dataSet->SetAbsciseLabelSerie('Abscise'); foreach ($this->lines as $name => $ordinateValues) { $dataSet->SetSerieName($name, $name); } $dataSet->SetYAxisUnit($this->ordinateStepTitle); $dataSet->SetXAxisUnit($this->absciseStepTitle); $chart = new pChart($this->maxWidth, $this->maxHeight); $chart->drawGraphAreaGradient(132, 153, 172, 50, TARGET_BACKGROUND); // Graph area setup $chart->setFontProperties(PCHART_FONTS_DIR . DIRECTORY_SEPARATOR . 'tahoma.ttf', 10); $chart->setGraphArea($this->graphMargins[0], $this->graphMargins[1], $this->maxWidth - $this->graphMargins[2], $this->maxHeight - $this->graphMargins[3]); $chart->drawGraphArea(213, 217, 221, FALSE); $ordinateScaleMargin = ($this->getMaxOrdinateValue() - $this->getMinOrdinateValue()) / $this->ordinateDevisions; $chart->setFixedScale($this->getMinOrdinateValue() - $ordinateScaleMargin, $this->getMaxOrdinateValue() + $ordinateScaleMargin, $this->ordinateDevisions); $chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 213, 217, 221, TRUE, 0, 2); $chart->drawGraphAreaGradient(162, 183, 202, 50); $chart->drawGrid(4, TRUE, 230, 230, 230, 20); // Draw the line chart // $chart->setShadowProperties(1, 1, 0, 0, 0, 30, 4); $chart->drawLineGraph($dataSet->GetData(), $dataSet->GetDataDescription()); $chart->clearShadow(); $chart->drawPlotGraph($dataSet->GetData(), $dataSet->GetDataDescription(), 5, 3, -1, -1, -1, TRUE); // Draw the legend $chart->drawLegend($this->maxWidth - $this->graphMargins[2] + 10, $this->graphMargins[1], $dataSet->GetDataDescription(), 236, 238, 240, 52, 58, 82); // Draw chart title if ($this->chartTitle) { $chart->drawTextBox(0, $this->maxHeight - 20, $this->maxWidth, $this->maxHeight, $this->chartTitle, 0, 255, 255, 255, ALIGN_RIGHT, TRUE, 0, 0, 0, 30); } // Render the picture $chart->addBorder(2); $chart->Render($this->outputFilepath); }
$maxNumber = $dbData[1][0][1]; for ($p = 0; $p < count($dbData[0]); $p++) { $data_server = $dbData[0][$p]; for ($i = 0; $i < count($data_server); $i++) { if ($i == 0) { $XAxis[] = date("H:i", $data_server[$i]); } else { $OLNum[] = $data_server[$i]; } } } $pChartDataSet = new pData(); $pChartDataSet->AddPoint($XAxis, "Serie1"); $pChartDataSet->AddPoint($OLNum, "Serie2"); $pChartDataSet->AddSerie("Serie2"); $pChartDataSet->RemoveSerie("Serie1"); $pChartDataSet->SetAbsciseLabelSerie("Serie1"); $pChartDataSet->SetYAxisName("在\n线\n人\n数\n//\n人"); $pChartDataSet->SetYAxisFormat("floor"); $pChartDataSet->SetXAxisFormat("number"); // 设置作图区域 $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);
$DataSet->SetAbsciseLabelSerie('SerieDate'); $DataSet->SetSerieName('Skill', 'SerieSkill'); $DataSet->SetSerieName('Session', 'SerieSession'); $Chart->setFontProperties(IMAGE_PATH . '/sig/font/DejaVuSans.ttf', 7); $DataSet->SetYAxisName('Skill'); $DataSet->SetYAxisUnit('K'); $Chart->setColorPalette(0, 255, 255, 0); $Chart->drawRightScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, $color['red'], $color['green'], $color['blue'], TRUE, 0, 0); $Chart->drawGrid(1, FALSE, 55, 55, 55, 100); $Chart->setShadowProperties(3, 3, 0, 0, 0, 30, 4); $Chart->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription()); $Chart->clearShadow(); $Chart->drawFilledCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 30); $Chart->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 1, 1, 255, 255, 255); $Chart->clearScale(); $DataSet->RemoveSerie('SerieSkill'); $DataSet->AddSerie('SerieSession'); $DataSet->SetYAxisName('Session'); $DataSet->SetYAxisUnit(''); $Chart->setColorPalette(1, 255, 0, 0); $Chart->setColorPalette(2, 0, 0, 255); $Chart->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, $color['red'], $color['green'], $color['blue'], TRUE, 0, 0); $Chart->setShadowProperties(3, 3, 0, 0, 0, 30, 4); $Chart->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription()); $Chart->clearShadow(); $Chart->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 1, 1, 255, 255, 255); $Chart->setFontProperties(IMAGE_PATH . '/sig/font/DejaVuSans.ttf', 7); $Chart->drawHorizontalLegend(235, -1, $DataSet->GetDataDescription(), 0, 0, 0, 0, 0, 0, $color['red'], $color['green'], $color['blue'], FALSE); } $cache_image = IMAGE_PATH . "/progress/trend_{$player}_{$last_time}.png"; $Chart->Render($cache_image);
return -1; } } } $DB->close(); // Build Bar Chart for zipcodes include "../pChart/pChart/pData.class"; include "../pChart/pChart/pChart.class"; $DataSet = new pData(); foreach ($zipcodes as $zipcode) { $DataSet->AddPoint($zipcode["quantity"], "Series1"); $DataSet->AddPoint($zipcode["zipcode"], "Series2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Series2"); $DataSet->SetSerieName("Sales By Zip Code", "Series1"); $DataSet->RemoveSerie("Series2"); } //$firephp->log($zipcodes); //$firephp->log($DataSet); // Initialise the graph $Test = new pChart(700, 230); $Test->setColorPalette(0, 38, 33, 204); $Test->setFontProperties("../pChart/Fonts/tahoma.ttf", 10); $Test->setGraphArea(50, 50, 680, 200); $Test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230); $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("../pChart/Fonts/tahoma.ttf", 14);
<?php /* Example23 : Playing with background bis */ // Standard inclusions include "../lib/pData.php"; include "../lib/pChart.php"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint(array(9, 9, 9, 10, 10, 11, 12, 14, 16, 17, 18, 18, 19, 19, 18, 15, 12, 10, 9), "Serie1"); $DataSet->AddPoint(array(10, 11, 11, 12, 12, 13, 14, 15, 17, 19, 22, 24, 23, 23, 22, 20, 18, 16, 14), "Serie2"); $DataSet->AddPoint(array(4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), "Serie3"); $DataSet->AddAllSeries(); $DataSet->RemoveSerie("Serie3"); $DataSet->SetAbsciseLabelSerie("Serie3"); $DataSet->SetSerieName("January", "Serie1"); $DataSet->SetSerieName("February", "Serie2"); $DataSet->SetYAxisName("Temperature"); $DataSet->SetYAxisUnit("°C"); $DataSet->SetXAxisUnit("h"); // Initialise the graph $Test = new pChart(700, 230); $Test->drawGraphAreaGradient(132, 173, 131, 50, TARGET_BACKGROUND); $Test->setFontProperties("../Fonts/tahoma.ttf", 8); $Test->setGraphArea(120, 20, 675, 190); $Test->drawGraphArea(213, 217, 221, FALSE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALL, 213, 217, 221, TRUE, 0, 2, TRUE); $Test->drawGraphAreaGradient(163, 203, 167, 50); $Test->drawGrid(4, TRUE, 230, 230, 230, 20); // Draw the bar chart
/** * 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; }
function knews_drawLine($values, $captions, $filename, $palette = "softtones_pro.txt", $legend = true) { // Dataset definition $DataSet = new pData(); $n = 1; foreach ($values as $value_serie) { $DataSet->AddPoint($value_serie, "Serie" . $n); $DataSet->SetSerieName($captions[$n], "Serie" . $n); if ($captions[$n] == '') { $DataSet->RemoveSerie("Serie" . $n); } $DataSet->AddSerie("Serie" . $n); $n++; } //$DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Serie" . ($n - 1)); $DataSet->SetYAxisName($captions[0]); // $DataSet->SetYAxisUnit("u"); // Initialise the graph $Test = new pChart(850, 230); $Test->loadColorPalette(KNEWS_DIR . "/includes/pChart/" . $palette); $Test->setFontProperties(KNEWS_DIR . "/includes/pChart/tahoma.ttf", 8); $Test->setGraphArea(60, 20, 820, 200); $Test->drawFilledRoundedRectangle(7, 7, 843, 223, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 845, 225, 5, 230, 230, 230); $Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 0, 2); $Test->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line $Test->setFontProperties(KNEWS_DIR . "/includes/pChart/tahoma.ttf", 6); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the line graph $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255); // Finish the graph //$DataSet->RemoveSerie("Serie1"); $Test->setFontProperties(KNEWS_DIR . "/includes/pChart/tahoma.ttf", 8); if ($legend) { $Test->drawLegend(75, 35, $DataSet->GetDataDescription(), 255, 255, 255); } $Test->setFontProperties(KNEWS_DIR . "/includes/pChart/tahoma.ttf", 10); //$Test->drawTitle(60,22,"example 1",50,50,50,585); $Test->Render(KNEWS_DIR . "/tmp/" . $filename); }
} else { $height = $width * 3 / 4; } $background = $backgrounds[$width]; $min_v_arrays = array(); foreach ($params['data'] as $a) { $min_v_arrays[] = $min_y_value; } // Dataset definition $DataSet = new pData(); $DataSet->AddPoint($params['data'], "Serie3"); $DataSet->AddPoint($min_v_arrays, "Serie4"); $DataSet->AddPoint($x_lable_arr, "x_lable_name"); $DataSet->SetAbsciseLabelSerie("x_lable_name"); $DataSet->AddAllSeries(); $DataSet->RemoveSerie("x_lable_name"); $DataSet->SetSerieName("", "Serie3"); // $DataSet->SetYAxisName("Kg"); // $DataSet->SetXAxisName("week"); $DataSet->SetSerieSymbol("Serie3", $normal_circle); $DataSet->SetSerieSymbolLastOne("Serie3", $last_circle); // Initialise the graph $Test = new pChart($width, $height); $Test->setFontPropertiesDir("{$pChart_dir}/Fonts"); // Add an image $Test->drawFromPNG($background, 0, 0); $Test->reportWarnings("GD"); $Test->setFixedScale($min_y_value, $max_y_value, 5); $Test->setFontProperties("{$pChart_dir}/Fonts/tahoma.ttf", 14); $Test->setGraphArea($area_margin_left, 20, $width - 30, $height - 55); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 255, 255, 255, TRUE, 0, 2, TRUE, 1);
/** * Generates a big graph with the number of best results * @param array */ static function generate_exercise_result_graph($attempts) { require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php'; require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php'; require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php'; $exercise_title = strip_tags($attempts['title']); $attempts = $attempts['data']; $my_exercise_result_array = $exercise_result = array(); if (empty($attempts)) { return null; } foreach ($attempts as $attempt) { if (api_get_user_id() == $attempt['exe_user_id']) { if ($attempt['exe_weighting'] != 0 ) { $my_exercise_result_array[]= $attempt['exe_result']/$attempt['exe_weighting']; } } else { if ($attempt['exe_weighting'] != 0 ) { $exercise_result[]= $attempt['exe_result']/$attempt['exe_weighting']; } } } //Getting best result rsort($my_exercise_result_array); $my_exercise_result = 0; if (isset($my_exercise_result_array[0])) { $my_exercise_result = $my_exercise_result_array[0] *100; } $max = 100; $pieces = 5 ; $part = round($max / $pieces); $x_axis = array(); $final_array = array(); $my_final_array = array(); for ($i=1; $i <=$pieces; $i++) { $sum = 1; if ($i == 1) { $sum = 0; } $min = ($i-1)*$part + $sum; $max = ($i)*$part; $x_axis[]= $min." - ".$max; $count = 0; foreach($exercise_result as $result) { $percentage = $result*100; //echo $percentage.' - '.$min.' - '.$max."<br />"; if ($percentage >= $min && $percentage <= $max) { //echo ' is > '; $count++; } } //echo '<br />'; $final_array[]= $count; if ($my_exercise_result >= $min && $my_exercise_result <= $max) { $my_final_array[] = 1; } else { $my_final_array[] = 0; } } //Fix to remove the data of the user with my data for($i = 0; $i<=count($my_final_array); $i++) { if (!empty($my_final_array[$i])) { $my_final_array[$i] = $final_array[$i] + 1; //Add my result $final_array[$i] = 0; } } $cache = new pCache(); // Dataset definition $data_set = new pData(); $data_set->AddPoint($final_array,"Serie1"); $data_set->AddPoint($my_final_array,"Serie2"); $data_set->AddPoint($x_axis,"Serie3"); $data_set->AddAllSeries(); $data_set->SetAbsciseLabelSerie('Serie3'); $data_set->SetSerieName(get_lang('Score'),"Serie1"); $data_set->SetSerieName(get_lang('MyResults'),"Serie2"); $data_set->SetXAxisName(get_lang("Score")); // Initialise the graph $main_width = 500; $main_height = 250; $main_graph = new pChart($main_width,$main_height); $main_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8); $main_graph->setGraphArea(50,30, $main_width -20,$main_height -50); $main_graph->drawFilledRoundedRectangle(10,10, $main_width- 10,$main_height -10,5,240,240,240); $main_graph->drawRoundedRectangle(7,7,$main_width - 7,$main_height - 7,5,230,230,230); $main_graph->drawGraphArea(255,255,255,TRUE); //SCALE_NORMAL, SCALE_START0, SCALE_ADDALLSTART0 $main_graph->drawScale($data_set->GetData(),$data_set->GetDataDescription(),SCALE_ADDALLSTART0, 150,150,150,TRUE,0,1,TRUE); $main_graph->drawGrid(4,TRUE,230,230,230,50); // Draw the 0 line $main_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',6); // $main_graph->drawTreshold(0,143,55,72,TRUE,TRUE); // Draw the bar graph $data_set->RemoveSerie("Serie3"); //$main_graph->drawBarGraph($data_set->GetData(),$data_set->GetDataDescription(),TRUE); //$main_graph->drawStackedBarGraph($data_set->GetData(),$data_set->GetDataDescription(),TRUE); $main_graph->drawOverlayBarGraph($data_set->GetData(),$data_set->GetDataDescription(), 100); // Finish the graph $main_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8); $main_graph->drawLegend($main_width - 120,$main_height -100,$data_set->GetDataDescription(),255,255,255); $main_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8); $main_graph->drawTitle(180,22,$exercise_title,50,50,50); $graph_id = 'exercise_result_graph'.Security::remove_XSS($_GET['course']).'-'.intval($_GET['session_id']).'-'.api_get_user_id(); if ($cache->IsInCache($graph_id, $data_set->GetData())) { //if (0) { //if we already created the img //echo 'in cache'; $img_file = $cache->GetHash($graph_id,$data_set->GetData()); } else { $cache->WriteToCache($graph_id, $data_set->GetData(), $main_graph); ob_start(); $main_graph->Stroke(); ob_end_clean(); $img_file = $cache->GetHash($graph_id, $data_set->GetData()); } $html = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">'; return $html; }
// Draw the graph $Test->drawFilledCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 30); if ($scale_hours <= 48) { $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 2, 1, 255, 255, 255); } // Draw labels if (!empty($ccities)) { foreach ($ccities as $k => $v) { $Test->setLabel($DataSet->GetData(), $DataSet->GetDataDescription(), "points", $k, "Städte: {$v}", 239, 233, 195); } } $Test->clearShadow(); // Clear the scale $Test->clearScale(); // Draw the 2nd graph $DataSet->RemoveSerie("points"); $DataSet->AddSerie("rank"); $DataSet->SetYAxisName("Rank"); $Test->drawRightScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_DIFF, 150, 150, 150, TRUE, 75, 0, FALSE, $skip_scale, TRUE); // Draw the 0 line $Test->setFontProperties("../charts/Fonts/tahoma.ttf", 6); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the Line graph $Test->drawFilledCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 20); if ($scale_hours <= 48) { $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 2, 1, 255, 255, 255); } // Draw Labels $Test->setFontProperties("../charts/Fonts/tahoma.ttf", 8); if (!empty($ally)) { foreach ($ally as $k => $v) {
<?php /* Example21 : A single stacked bar graph */ // Standard inclusions include "src/pData.php"; include "src/pChart.php"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint(array(1, 2, 5), "Serie1"); $DataSet->AddPoint(array(3, 2, 2), "Serie2"); $DataSet->AddPoint(array(3, 4, 1), "Serie3"); $DataSet->AddPoint(array("A#~1", "A#~2", "A#~3"), "Labels"); $DataSet->AddAllSeries(); $DataSet->RemoveSerie("Labels"); $DataSet->SetAbsciseLabelSerie("Labels"); $DataSet->SetSerieName("Alpha", "Serie1"); $DataSet->SetSerieName("Beta", "Serie2"); $DataSet->SetSerieName("Gama", "Serie3"); $DataSet->SetXAxisName("Samples IDs"); $DataSet->SetYAxisName("Test Marker"); $DataSet->SetYAxisUnit("µm"); // Initialise the graph $Test = new pChart(380, 400); $Test->drawGraphAreaGradient(90, 90, 90, 90, TARGET_BACKGROUND); // Graph area setup $Test->setFontProperties("Fonts/pf_arma_five.ttf", 6); $Test->setGraphArea(110, 180, 350, 360); $Test->drawGraphArea(213, 217, 221, FALSE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALLSTART0, 213, 217, 221, TRUE, 0, 2, TRUE);
} } } } if (!empty($showchart)) { if ($charttype == "summary") { // Initialise the graph $Test = new pChart(700, 230); $Test->setFontProperties($CFG->dirroot . "/local/iomad/pchart/Fonts/tahoma.ttf", 8); $Test->setGraphArea(65, 30, 125, 200); $Test->drawFilledRoundedRectangle(7, 7, 203, 223, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 205, 225, 5, 230, 230, 230); $Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawScale($chartdata->GetData(), $chartdata->GetDataDescription(), SCALE_ADDALLSTART0, 150, 150, 150, TRUE, 0, 2, TRUE); $Test->drawGrid(4, TRUE, 230, 230, 230, 50); $chartdata->RemoveSerie("Serie4"); // Draw the 0 line $Test->setFontProperties("Fonts/tahoma.ttf", 6); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the bar graph $Test->drawBarGraph($chartdata->GetData(), $chartdata->GetDataDescription(), 80); // Finish the graph $Test->setFontProperties($CFG->dirroot . "/local/iomad/pchart/Fonts/tahoma.ttf", 8); $Test->drawLegend(135, 150, $chartdata->GetDataDescription(), 255, 255, 255); $Test->setFontProperties($CFG->dirroot . "/local/iomad/pchart/Fonts/tahoma.ttf", 10); $Test->drawTitle(0, 22, "Sample size", 50, 50, 50, 210); $Test->Stroke("SmallStacked.png"); exit; } else { if ($charttype == "course") { // Initialise the graph
function grafico($dados, $eixo, $cor1, $grafico, $situacao, $legenda) { include_once "pChart/pChart/pData.class"; include_once "pChart/pChart/pChart.class"; $DataSet = new pData(); $DataSet->AddPoint($dados, "Serie1"); $DataSet->AddPoint($eixo, "Serie2"); $DataSet->AddAllSeries(); $DataSet->RemoveSerie("Serie2"); $DataSet->SetAbsciseLabelSerie("Serie2"); $DataSet->SetSerieName($legenda, "Serie1"); $Test = new pChart(720, 430); $Test->drawGraphAreaGradient($cor1, 173, 131, 50, TARGET_BACKGROUND); $Test->setFontProperties("pChart/Fonts/tahoma.ttf", 8); $Test->setGraphArea(50, 80, 675, 390); $Test->drawGraphArea(217, 217, 211, FALSE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALL, 213, 217, 221, TRUE, 0, 2, TRUE); $Test->drawGraphAreaGradient(163, 203, 167, 50); $Test->drawGrid(4, TRUE, 230, 230, 230, 20); $Test->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 70); $Title = "{$situacao}"; $Test->setFontProperties("pChart/Fonts/tahoma.ttf", 14); $Test->drawTextBox(0, 0, 700, 60, $Title, 0, 255, 255, 255, ALIGN_CENTER, TRUE, 30, 0, 0, 30); $Test->setFontProperties("pChart/Fonts/tahoma.ttf", 9); $Test->drawLegend(520, 70, $DataSet->GetDataDescription(), 236, 238, 240, 52, 58, 82); $Test->addBorder(2); $Test->Render("images/" . $grafico); }
function cartesianChart($type, $x, $y, $w, $h, $imgname = '', $config = array()) { $w -= 4; $h -= 4; $settings = array('FontName' => 'tahoma.ttf', 'FontSize' => 8, 'LegendFontSize' => 8, 'LegendFontName' => 'tahoma.ttf', 'Logo' => '', 'LogoTransparency' => 20, 'XAxisFormat' => 'number', 'XAxisUnit' => '', 'YAxisFormat' => 'number', 'YAxisUnit' => '', 'XLogo' => 0, 'YLogo' => 0, 'Xlabel' => 'x label', 'XAngle' => 0, 'Ylabel' => 'y label', 'Legend' => '', 'Textbox' => '', 'TextboxFontSize' => 8, 'TextboxFontName' => 'tahoma.ttf', 'ImgR' => 132, 'ImgG' => 173, 'ImgB' => 131, 'Decay' => 80, 'BGR' => 163, 'BGG' => 203, 'BGB' => 167, 'Decay2' => 80, 'Filled' => '', 'DataR' => 191, 'DataG' => 120, 'DataB' => 71, 'LBR' => 226, 'LBG' => 228, 'LBB' => 230, 'LR' => 0, 'LG' => 0, 'LB' => 0); // Get the custom settings if (is_array($config)) { foreach ($config as $key => $val) { $settings[$key] = $val; } } $DataSet = new pData(); $DataSet->AddPoint($y, "Serie1"); $DataSet->AddPoint($x, "Serie2"); $DataSet->AddAllSeries(); $DataSet->RemoveSerie("Serie2"); $DataSet->SetAbsciseLabelSerie("Serie2"); $DataSet->SetSerieName($settings['Legend'], "Serie1"); $DataSet->SetYAxisName($settings['Ylabel']); $DataSet->SetXAxisName($settings['Xlabel']); $DataSet->SetXAxisFormat($settings['XAxisFormat']); if (strlen($settings['XAxisUnit'])) { $DataSet->SetXAxisUnit($settings['XAxisUnit']); } if (strlen($settings['YAxisUnit'])) { $DataSet->SetYAxisUnit($settings['YAxisUnit']); } $DataSet->SetYAxisFormat($settings['YAxisFormat']); // Initialise the graph $Test = new pChart($w, $h); $Test->drawGraphAreaGradient($settings['ImgR'], $settings['ImgG'], $settings['ImgB'], $settings['Decay'], TARGET_BACKGROUND); $FontSize = $settings['FontSize']; $FontName = $this->_ext_path . "/fonts/" . $settings['FontName']; $Test->setFontProperties($FontName, $FontSize); //Calc Textbox Height if (strlen($settings['Textbox'])) { $TextboxFontSize = $settings['TextboxFontSize']; $TextboxFontName = $this->_ext_path . "/fonts/" . $settings['TextboxFontName']; $Position = imageftbbox($TextboxFontSize, 0, $TextboxFontName, $settings['Textbox']); $TextboxHeight = $Position[1] - $Position[7] + 8; } else { $TextboxHeight = 0; } // Maximize The graph area //on Y axis if ($settings['XAxisFormat'] == 'time') { $xdata = "99:99:99"; $Position = imageftbbox($FontSize, 0, $FontName, $xdata); $WXmax = $Position[2] - $Position[0]; $TextHeightX = $Position[1] - $Position[7]; } elseif ($settings['XAxisFormat'] == 'date') { $xdata = "99/99/9999"; $Position = imageftbbox($FontSize, 0, $FontName, $xdata); $WXmax = $Position[2] - $Position[0]; $TextHeightX = $Position[1] - $Position[7]; } else { $WXmax = 0; foreach ($x as $xdata) { $xdata .= $settings['XAxisUnit']; $Position = imageftbbox($FontSize, 0, $FontName, $xdata); $TextWidth = $Position[2] - $Position[0]; $TextHeightX = $Position[1] - $Position[7]; $WXmax = $TextWidth > $WXmax ? $TextWidth : $WXmax; } } if ($settings['XAngle'] > 0) { $sin = abs(sin(deg2rad($settings['XAngle']))); $cos = abs(cos(deg2rad($settings['XAngle']))); $HXmax = $WXmax * $sin + $TextHeightX * $cos; } else { $HXmax = $TextHeightX; } //on Y axis... if ($settings['YAxisFormat'] == 'time') { $ydata = "99:99:99"; $Position = imageftbbox($FontSize, 0, $FontName, $ydata); $WYmax = $Position[2] - $Position[0]; $TextHeightY = $Position[1] - $Position[7]; } elseif ($settings['YAxisFormat'] == 'date') { $ydata = "99/99/9999"; $Position = imageftbbox($FontSize, 0, $FontName, $ydata); $WYmax = $Position[2] - $Position[0]; $TextHeightY = $Position[1] - $Position[7]; } else { $WYmax = 0; foreach ($y as $ydata) { $ydata .= $settings['YAxisUnit']; //echo $ydata."<br>"; $Position = imageftbbox($FontSize, 0, $FontName, $ydata); $TextWidth = $Position[2] - $Position[0]; $TextHeightY = $Position[1] - $Position[7]; $WYmax = $TextWidth > $WYmax ? $TextWidth : $WYmax; } } $Test->setGraphArea($WYmax + $TextHeightY + 35, 20, $w - 25, $h - $HXmax - $TextHeightX - $TextboxHeight - 20); //$Test->setGraphArea(60,20,$w-25,($settings['XAngle']==0)?$h-70:$h-100); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALL, 213, 217, 221, TRUE, $settings['XAngle'], 0, TRUE); $Test->drawGraphAreaGradient($settings['BGR'], $settings['BGG'], $settings['BGB'], $settings['Decay2']); $Test->drawGrid(4, TRUE, 230, 230, 230, 20); // This will put the picture "logo.png" with transparency if (strlen($settings['Logo'])) { $XLogo = $WYmax + $TextHeightY + 35 + $settings['XLogo']; $YLogo = 20 + $settings['XLogo']; $logo = $settings['Logo']; //Fing extension of logo : png,gif or jpg if ($this->_findexts($logo) == "png") { echo "png!"; $Test->drawFromPNG($logo, $XLogo, $YLogo, $settings['LogoTransparency']); } elseif ($this->_findexts($logo) == "gif") { echo "gif!"; $Test->drawFromGIF($logo, $XLogo, $YLogo, $settings['LogoTransparency']); } elseif ($this->_findexts($logo) == "jpg") { echo "jpg"; $Test->drawFromJPG($logo, $XLogo, $YLogo, $settings['LogoTransparency']); } } $Test->setColorPalette(0, $settings['DataR'], $settings['DataG'], $settings['DataB']); if ($type == "bar") { // Draw the bar chart $Test->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 70); } elseif ($type == "line") { $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 0, -1, -1, -1, TRUE); } elseif ($type == "cubic") { $Test->setShadowProperties(3, 3, 0, 0, 0, 30, 4); $Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->clearShadow(); if ($settings['Filled'] == 'yes') { $Test->drawFilledCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 30); } $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 0, -1, -1, -1, TRUE); } // Draw the textbox if (strlen($settings['Textbox'])) { $Test->setFontProperties($TextboxFontName, $TextboxFontSize); $Test->drawTextBox(0, $h - $TextboxHeight, $w, $h, $settings['Textbox'], 0, 255, 255, 255, ALIGN_CENTER, TRUE, 0, 0, 0, 30); } // Draw the legend if (strlen($settings['Legend'])) { $LegendFontSize = $settings['LegendFontSize']; $LegendFontName = $this->_ext_path . "/fonts/" . $settings['LegendFontName']; $Position = imageftbbox($LegendFontSize, 0, $LegendFontName, $settings['Legend']); $LegendW = $Position[2] - $Position[0] + 40; $Test->setFontProperties($LegendFontName, $LegendFontSize); $Test->drawLegend($w - $LegendW, 10, $DataSet->GetDataDescription(), $settings['LBR'], $settings['LBG'], $settings['LBB'], 52, 58, 82, $settings['LR'], $settings['LG'], $settings['LB'], TRUE); } // Render the picture $Test->addBorder(2); if (strlen($imgname)) { //custom image name $imgname = $this->_img_path . "/" . $imgname; } else { $this->obj->load->helper('string'); $imgname = $this->_img_path . "/{$type}-" . random_string('alnum', 16) . ".png"; } $Test->Render($imgname); return array("name" => '/' . $imgname, "w" => $w + 4, "h" => $h + 4); }