ASNMTAP
view release on metacpan or search on metacpan
applications/htmlroot/cgi-bin/generateChart.pl view on Meta::CPAN
# 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
$layer->addDataSet(\@avg1, 0xcf4040, "$applicationTitle1")->setDataSymbol($perlchartdir::DiamondSymbol, 8);
if ($uKey2 ne 'none') { $layer->addDataSet(\@avg2, 0x6699cc, "$applicationTitle2")->setDataSymbol($perlchartdir::DiamondSymbol, 8); }
if ($uKey3 ne 'none') { $layer->addDataSet(\@avg3, 0x009900, "$applicationTitle3")->setDataSymbol($perlchartdir::DiamondSymbol, 8); }
# Enable data label on the data points.
$layer->setDataLabelFormat("{value|2,.}");
}
# Set the bar border to transparent
$layer->setBorderColor($perlchartdir::Transparent);
if ($pf eq 'on') {
$c->addLegend(2, $hight - 32, 0, "arial.ttf", 8)->setBackground($perlchartdir::Transparent);
} else {
$c->addLegend(2, $hight - 32, 0, "arial.ttf", 8)->setFontColor($forGround);
}
}
}
# Output the chart
binmode(STDOUT);
print "Content-type: image/png\n\n";
print $c->makeChart2($perlchartdir::PNG);
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub getAverage {
my ($number, $dbh, $rv, $uKey, $sqlStartDate, $sqlEndDate, $sqlPeriode, $selChart, $debug) = @_;
my ($sql, $sth, $errorMessage, $dbiErrorCode, $dbiErrorString, $startDate, $hour, $average, @avg, @labels);
if ( $selChart eq "HourlyAverage" ) {
$sql = create_sql_query_events_from_range_year_month ($inputType, $sqlStartDate, $sqlEndDate, "select SQL_NO_CACHE startDate, hour(startTime) as hour, round(avg(time_to_sec(duration)), 2)", $forceIndex, "WHERE catalogID = '$CcatalogID' and uKey =...
} else {
$sql = create_sql_query_events_from_range_year_month ($inputType, $sqlStartDate, $sqlEndDate, "select SQL_NO_CACHE startDate, round(avg(time_to_sec(duration)), 2)", $forceIndex, "WHERE catalogID = '$CcatalogID' and uKey = '$uKey'", $sqlPeriode, "...
}
$sth = $dbh->prepare( $sql ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot dbh->prepare: $sql", $debug, '', "", '', "", 0, '', $sessionID);
$sth->execute() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->execute: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv;
if ( $selChart eq "HourlyAverage" ) {
$sth->bind_columns( \$startDate, \$hour, \$average ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->bind_columns: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv;
} else {
$sth->bind_columns( \$startDate, \$average ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->bind_columns: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv;
}
if ( $rv ) {
if ( $sth->rows ) {
while( $sth->fetch() ) {
push (@avg, $average);
if ( $selChart eq "HourlyAverage" ) {
push (@labels, $startDate .":". $hour);
} else {
push (@labels, $startDate);
}
}
} else {
$hight = 380; $rv = 0; $errorMessage = "NO DATA FOR THIS PERIOD (3)";
}
( run in 0.662 second using v1.01-cache-2.11-cpan-39bf76dae61 )