コード例 #1
0
ファイル: chart_index.php プロジェクト: Kervinou/OBM
function dis_chart_bar_multiple($chart) {
  global $chart_colors;

  $title = $chart["title"];
  $xlabels = $chart["xlabels"];
  $values = $chart["plots"]["values"];
  $labels = $chart["plots"]["labels"];
  $legends = $chart["plots"]["legends"];
  $new_bar = $chart["plots"]["new_bar"];

  $graph = new Graph(600, 250);
  $graph->setAntiAliasing(TRUE);
  $graph->setBackgroundColor(new Color(240, 240, 240));
  $group = new PlotGroup;
  $group->grid->hideVertical();
  $group->setPadding(45, 22 ,30, 40);
  $group->setSpace(3, 3, NULL, NULL);
  $group->legend->setAlign(NULL, LEGEND_TOP);
  $group->legend->setPosition(1,0);

  // X axis Labels infos
  $xlabel = new Label($xlabels);
  $group->axis->bottom->setlabelText($xlabels);

  // Title infos
  if ($title != "") {
    $graph->title->set("$title");
  }

  $num = 0;
  $nb_bars = array_sum($new_bar);
  $num_bar = 0;

  // $num_plot is the plot number
  // $num_bar is the bar number (1 bar can cumul more than one plot)
  foreach ($values as $num_plot => $plot_values) {
    // Chart infos : colors, size, shadow
    if ($new_bar[$num_plot] == 1) {
      $num_bar++;
    }
    $plot = new BarPlot($plot_values, $num_bar, $nb_bars);
    $plot->setBarColor(new Color($chart_colors[$num_plot][0], $chart_colors[$num_plot][1], $chart_colors[$num_plot][2]));
    $plot->setBarSize(0.6);
    if ($new_bar[$num_plot] == 1) {
      $plot->barShadow->setSize(2);
      $plot->barShadow->smooth(TRUE);
      // Labels infos
      $label = new Label($labels[$num_plot]);
      $label->setFont(new Tuffy(8));
      $label->setAlign(NULL, LABEL_TOP);
      $plot->label = $label;
    }
    $group->add($plot);
    $group->legend->add($plot, utf8_decode($legends[$num_plot]), LEGEND_BACKGROUND);
  }

  $graph->add($group);
  $graph->draw();
}
コード例 #2
0
$plot->barShadow->smooth(TRUE);
$mois = array('Jan', 'Fév', 'Mar', 'Avr', 'Mai', 'Jun', 'Juil', 'Août', 'Sept', 'Oct', 'Nov', 'Déc');
$label = array();
foreach ($mois as $m) {
    $label[] = $m;
}
$label[] = ' ';
foreach ($mois as $m) {
    $label[] = $m;
}
$plot->xAxis->setLabelText($label);
/* ICI */
$max = array_max($values);
$yValues = array();
for ($i = 0; $i <= $max; $i++) {
    $yValues[] = $i;
}
$plot->yAxis->setLabelText($yValues);
// Image::drawError(var_export($yValues, TRUE));
$plot->yAxis->setLabelText($yValues);
$plot->setPadding(30, 5, 20, 15);
$labelAvant = new Label("2005");
$labelAvant->setFont(new TTFFont(ARTICHOW_FONT . '/TuffyBold.ttf', 12));
$labelAvant->move(180, 10);
$labelMaintenant = new Label("2006");
$labelMaintenant->setFont(new TTFFont(ARTICHOW_FONT . '/TuffyBold.ttf', 12));
$labelMaintenant->move(450, 10);
$graph->add($plot);
$graph->addLabel($labelAvant, 0, 0);
$graph->addLabel($labelMaintenant, 0, 0);
$graph->draw();
コード例 #3
0
 public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing)
 {
     $this->label->setFont(new Tuffy(8));
     $datayReal = $this->datay;
     $dataySkewed = array();
     for ($index = 0; $index < count($this->datay); $index++) {
         $dataySkewed[$index] = false;
     }
     $count = count($this->datay);
     $max = $this->getRealYMax(NULL);
     $min = $this->getRealYMin(NULL);
     // Find zero for bars
     if ($this->xAxisZero and $min <= 0 and $max >= 0) {
         $zero = 0;
     } else {
         if ($max < 0) {
             $zero = $max;
         } else {
             $zero = $min;
         }
     }
     // Get base position
     $zero = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, $zero));
     // Distance between two values on the graph
     $distance = $this->xAxis->getDistance(0, 1);
     // Compute paddings
     $leftPadding = $this->barPadding->left * $distance;
     $rightPadding = $this->barPadding->right * $distance;
     $padding = $leftPadding + $rightPadding;
     $space = $this->barSpace * ($this->number - 1);
     $barSize = ($distance - $padding - $space) / $this->number;
     $barPosition = $leftPadding + $barSize * ($this->identifier - 1);
     for ($key = 0; $key < $count; $key++) {
         $value = $this->datay[$key];
         if ($value !== NULL) {
             /* Determine if we should use cut symbol */
             $position = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $value));
             $barStart = $barPosition + ($this->identifier - 1) * $this->barSpace + $position->x;
             $barStop = $barStart + $barSize;
             $t1 = min($zero->y, $position->y);
             $t2 = max($zero->y, $position->y);
             if (round($t2 - $t1) == 0) {
                 continue;
             }
             if ($dataySkewed[$key]) {
                 $xmin = round($t1) - $this->depth + $this->move->top;
                 $xmax = round($t2) - $this->depth + $this->move->top;
                 $dividerPoint = ($xmax - $xmin) * 0.2 + $xmin;
                 $p1x = round($barStart) + $this->depth + $this->move->left;
                 $p1y = round($t1) - $this->depth + $this->move->top;
                 $p2x = round($barStop) + $this->depth + $this->move->left;
                 $p2y = round($t2) - $this->depth + $this->move->top;
                 $p1 = new awPoint($p1x, $p1y);
                 $p2 = new awPoint($p2x, $p2y);
                 $this->drawBar($drawer, $p1, $p2, $key);
                 $lineX = round($barStop) + $this->depth + $this->move->left;
                 $lineY = $dividerPoint;
                 /* Draw a two-pixel white line over the bar at the divider point. */
                 $white = imagecolorallocate($drawer->resource, 255, 255, 255);
                 imageline($drawer->resource, $lineX - $barSize + 1, $lineY, $lineX + 1, $lineY, $white);
                 imageline($drawer->resource, $lineX - $barSize + 1, $lineY + 1, $lineX + 1, $lineY + 1, $white);
             } else {
                 $p1 = new awPoint(round($barStart) + $this->depth + $this->move->left, round($t1) - $this->depth + $this->move->top);
                 $p2 = new awPoint(round($barStop) + $this->depth + $this->move->left, round($t2) - $this->depth + $this->move->top);
                 $this->drawBar($drawer, $p1, $p2, $key);
             }
         }
     }
     $maxValue = $this->maxValue;
     // Draw labels
     foreach ($datayReal as $key => $value) {
         if ($value !== NULL) {
             if ($value > $maxValue) {
                 $maxValue = $value;
             }
             $position = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $this->datay[$key]));
             $position2 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $this->datay[$key] / 2));
             $point = new awPoint($barPosition + ($this->identifier - 1) * $this->barSpace + $position->x + $barSize / 2 + 1 + $this->depth, $position->y - $this->depth);
             $point2 = new awPoint($barPosition + ($this->identifier - 1) * $this->barSpace + $position2->x + $barSize / 2 + 1 + $this->depth, $position2->y - $this->depth);
             if ($maxValue == 0) {
                 $maxValue = 1;
             }
             if ($value != 0 && $this->drawPercent) {
                 /* Mode 2 is the white box number at the top of the bar */
                 $this->label->drawSpecial($drawer, $point2, $key, $value);
                 //$this->label->draw($drawer, $point, $key);
             }
         }
     }
     switch ($this->view) {
         case DASHBOARD_GRAPH_YEARLY:
             $tabImage = imagecreatefrompng('images/tab3.png');
             imagecopy($drawer->resource, $tabImage, 399, 0, 0, 0, 63, 73);
             break;
         case DASHBOARD_GRAPH_MONTHLY:
             $tabImage = imagecreatefrompng('images/tab2.png');
             imagecopy($drawer->resource, $tabImage, 399, 0, 0, 0, 63, 73);
             break;
         case DASHBOARD_GRAPH_WEEKLY:
         default:
             $tabImage = imagecreatefrompng('images/tab1.png');
             imagecopy($drawer->resource, $tabImage, 399, 0, 0, 0, 63, 73);
             break;
     }
     if ($this->noData) {
         $noDataImage = imagecreatefromjpeg('images/graphNoData.jpg');
         imagecopy($drawer->resource, $noDataImage, 27, 13, 0, 0, 363, 195);
     }
 }