ASNMTAP

 view release on metacpan or  search on metacpan

applications/htmlroot/cgi-bin/generateChart.pl  view on Meta::CPAN

  # Set the center of the pie at (<>, <>) and the radius to <> pixels
  $c->setPieSize($width/2, $hight/2, 130);

  # Draw the pie in 3D
  $c->set3D();
} else {
  # Create XYChart object with: width, hight, backgroundcolor, bordercolor, pxp-3d borden
  $c = new XYChart($width, $hight, $background, $background, 0);

  # Set the plotarea at (xOffset, yOffset) and of size $width - 95 x $hight - 78 pixels, with white background. Set border and grid line colors to 0xa08040.
  $c->setPlotArea($xOffset, $yOffset, $width - 95, $hight - $AreaBOffset, 0xffffff, -1, 0xaCCCCCC, 0xaCCCCCC, 0xaCCCCCC);

  # Set the axes width to 1 pixels
  $c->xAxis()->setWidth(1);
  $c->yAxis()->setWidth(1);

  # Set the axis colors
  $c->xAxis()->setColors($axisColor);
  $c->yAxis()->setColors($axisColor);

  # Add a title on the the y axis
  my $yAxisTitle = ($selChart eq 'Bar') ? 'Response time' : 'Average response time';
  $c->yAxis()->setTitle($yAxisTitle, "arial.ttf", 9, $forGround);

  # Add a title on the the x axis
  $c->xAxis()->setTitle("<*block,valign=absmiddle*>Date/Time<*/*>")->setFontColor($forGround);
}

# Add a title box to the chart using 10 pts Arial Bold Italic font.
$chartTitle = "Error for '$prgtext'" unless ( defined $chartTitle and $rv );
$c->addText($width/2, 14, $chartTitle, "arialbi.ttf", 10, $forGround, 5, 0);

# Add debugMessage and errorMessage
$c->addText($width - 18, $hight - 33, $debugMessage, "arial.ttf", 8, $forGround, 6, 0) if ( defined $debugMessage );
$c->addText($width/2, (($hight - $yOffset - $AreaBOffset)/2) + $yOffset + 16, $errorMessage, "arial.ttf", 12, 0xFF0000, 5, 0) if ( defined $errorMessage );
$c->addText($width/2, (($hight - $yOffset - $AreaBOffset)/2) + $yOffset - 16, $dbiErrorCode, "arial.ttf", 10, 0xFF0000, 5, 0) if ( defined $dbiErrorCode );
$c->addText($width/2, (($hight - $yOffset - $AreaBOffset)/2) + $yOffset + 48, $dbiErrorString, "arial.ttf", 10, 0xFF0000, 5, 0) if ( defined $dbiErrorString );

# Add a custom CDML text at the bottom right of the plot area as the logo
$c->addText($width - 3, 92, $APPLICATION . " @ " . $BUSINESS, "arial.ttf", 8, $forGround, 6, 270);
$c->addText($width - 18, $hight - 18, $DEPARTMENT . " @ " . $BUSINESS . ", created on: " . scalar(localtime()) . ".", "arial.ttf", 8, $forGround, 6, 0);

if ( $rv ) {
  if ( $selChart eq "Status" or $selChart eq "ErrorDetails" ) {
    # use given color array as the data colors (sector colors)
    if ( $selChart eq "Status" ) {
      my (@colors);
      foreach my $label (@labels) { push (@colors, $COLORSPIE {$label} ); }
      $c->setColors2($perlchartdir::DataColor, \@colors);

      # Add icons to the chart as a custom field
      $c->addExtraField(\@icons);
    } elsif ( $selChart eq "ErrorDetails" ) {
      my $colors = [0xb8bc9c, 0xecf0b9, 0x999966, 0x333366, 0xc3c3e6, 0x594330,0xa0bdc4];
      $c->setColors2($perlchartdir::DataColor, $colors);
    }

    # Use the side label layout method
    $c->setLabelLayout($perlchartdir::SideLayout);
    $c->setLabelStyle("tahoma.ttf", 8, $forGround)->setBackground($perlchartdir::Transparent, $perlchartdir::Transparent, 0);
    $c->setLabelFormat("<*block,valign=absmiddle*><*img={field0}*> {label} (#{value} - {percent}%)");

    # Set the border color of the sector the same color as the fill color. Set the line color of the join line to forgroundcolor
    $c->setLineColor($perlchartdir::SameAsMainColor, $forGround);

    # Set the start angle to 135 degrees
    $c->setStartAngle(135);

    # Set the pie data and the pie labels
    $c->setData(\@data, \@labels);
  } else {
    # Set the labels on the x & y axis
    my $fontAngel = ( $selChart eq "HourlyAverage" ) ? 0 : 45;
    $c->xAxis()->setLabelStyle("Arial.ttf", 8, $forGround)->setFontAngle($fontAngel);
    $c->xAxis()->setLabels(\@labels);
    $c->yAxis()->setLabelStyle("Arial.ttf", 8, $forGround)->setFontAngle(0);
    $c->yAxis()->setLabelFormat("{value|2,.}");

    # Set the margins at the two ends of the axis during auto-scaling, and whether to start the axis from zero.
    $c->yAxis()->setAutoScale(5, 10, 0);

    # Add a mark line ore zone to the chart and add the first two data sets to the chart as a stacked bar group
    if ( $uKey2 eq 'none' and $uKey3 eq 'none' ) {
      $trendvalue = 3600 if ($trendvalue == 0);
      $trendvalue += 0.05;
      $c->yAxis()->addZone($trendvalue, 3600, $trendZone) if ($trendvalue != 0);
    }

    $c->yAxis()->addZone(0, -6, $trendZone);
	  my $layer;
	
    if ( $selChart eq "Bar" ) {
      # Add a line layer to the chart
      $layer = $c->addBarLayer2($perlchartdir::Stack);

      # Set the sub-bar gap to 0, so there is no gap between stacked bars with a group
      $layer->setBarGap(-1.7E-100, 0);
	
      # Add the first two data sets to the chart as a stacked bar group
      $layer->addDataSet(\@dataOK, $layer->yZoneColor($trendvalue, $COLORSRRD {OK}, $COLORSRRD {TRENDLINE}), " Duration");
      $layer->addDataSet(\@dataWarning,  $COLORSRRD {WARNING},  " Warning");
      $layer->addDataSet(\@dataCritical, $COLORSRRD {CRITICAL}, " Critical");
      $layer->addDataSet(\@dataUnknown,  $COLORSRRD {UNKNOWN},  " Unknown");
      $layer->addDataSet(\@dataOffline,  $COLORSRRD {OFFLINE},  " Offline");
      $layer->addDataSet(\@dataNoTest,   $COLORSRRD {"NO TEST"},  " No Test");
    } elsif ( $selChart eq "HourlyAverage" or $selChart eq "DailyAverage" ) {
      if ( $selChart eq "HourlyAverage" ) {
        for($i = 1; $i < $numberOfDays; ++$i) { my $xMark1 = $c->xAxis()->addMark((24 * $i), 0x0000FF); }
        my $xCorrectie = 95 - $xOffset;

        for($i = 0; $i < $numberOfDays; ++$i) {
          my $cdate = Date_to_Text_Long ( Add_Delta_Days($yearFrom, $monthFrom, $dayFrom, $i) );
          my $x = ($numberOfDays > 1) ? ($i * 600) + 300 + $xCorrectie : ($width/2) + $xCorrectie;
          $c->addText($x, 40, $cdate, "arialbi.ttf", 10, 0x000000, 5, 0);
        }
      }

      # Add a line layer to the chart
      $layer = $c->addSplineLayer();

      # Add the first two data sets to the chart as a stacked bar group



( run in 1.138 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )