fixed error library pdf example

This commit is contained in:
daniel 2018-05-22 13:15:09 +02:00
parent 9f140e6197
commit 727b173392
1 changed files with 131 additions and 224 deletions

View File

@ -27,6 +27,7 @@ include_once("pChart/pScatter.class.php");
include_once("pChart/pRadar.class.php"); include_once("pChart/pRadar.class.php");
// Define default fine colors // Define default fine colors
$default_fine_colors = array(); $default_fine_colors = array();
$default_fine_colors[] = "#2222FF"; $default_fine_colors[] = "#2222FF";
$default_fine_colors[] = "#00DD00"; $default_fine_colors[] = "#00DD00";
@ -71,9 +72,6 @@ if (!$graph) {
} }
$data = $graph['data']; $data = $graph['data'];
html_debug_print($data, true);
$width = $graph['width']; $width = $graph['width'];
$height = $graph['height']; $height = $graph['height'];
@ -885,134 +883,18 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height,
global $config; global $config;
/* CAT:Vertical Charts */ html_debug_print($graph_type, true);
/* html_debug_print($index, true);
if (!is_array($legend) || empty($legend)) { html_debug_print($data, true);
unset($legend);
}
if (is_array(reset($data))) {
$data2 = array();
foreach ($data as $i =>$values) {
$c = 0;
foreach ($values as $i2 => $value) {
$data2[$i2][$i] = $value;
$c++;
}
}
$data = $data2;
}
else {
$data = array($data);
}
*/
/* Create and populate the pData object */
/*
$MyData = new pData();
foreach ($data as $i => $values) {
if (isset($legend)) {
$point_id = $legend[$i];
// Translate the id of serie to legend of id
if (!empty($series_type)) {
if (!isset($series_type[$point_id])) {
$series_type[$point_id] = $series_type[$i];
unset($series_type[$i]);
}
}
}
else {
$point_id = $i;
}
$MyData->addPoints($values, $point_id);
if (!empty($rgb_color)) {
$MyData->setPalette($point_id,
array(
"R" => $rgb_color[$i]['color']["R"],
"G" => $rgb_color[$i]['color']["G"],
"B" => $rgb_color[$i]['color']["B"],
"BorderR" => $rgb_color[$i]['border']["R"],
"BorderG" => $rgb_color[$i]['border']["G"],
"BorderB" => $rgb_color[$i]['border']["B"],
"Alpha" => $rgb_color[$i]['alpha']));
$palette_color = array();
if (isset($rgb_color[$i]['color'])) {
$palette_color["R"] = $rgb_color[$i]['color']["R"];
$palette_color["G"] = $rgb_color[$i]['color']["G"];
$palette_color["B"] = $rgb_color[$i]['color']["B"];
}
if (isset($rgb_color[$i]['color'])) {
$palette_color["BorderR"] = $rgb_color[$i]['border']["R"];
$palette_color["BorderG"] = $rgb_color[$i]['border']["G"];
$palette_color["BorderB"] = $rgb_color[$i]['border']["B"];
}
if (isset($rgb_color[$i]['color'])) {
$palette_color["Alpha"] = $rgb_color[$i]['Alpha'];
}
$MyData->setPalette($point_id, $palette_color);
}
// The weight of the line is not calculated in pixels, so it needs to be transformed
$reduction_coefficient = 0.31;
$MyData->setSerieWeight($point_id, $config['custom_graph_width'] * $reduction_coefficient);
}
*/
/*
$MyData = new pData();
$MyData->addPoints(array(0.11, 0.91, 0.58, 1.11),"Probe 1");
$MyData->setAxisName(0,"Temperatures");
$MyData->addPoints(array(1328112000, 1328126400, 1330610400, 1330610420),"Labels");
$MyData->setAbscissa("Labels");
$MyData->setXAxisDisplay(AXIS_FORMAT_TIME,"d/m\nH:i");
*/
/*
$MyData = new pData();
$MyData->addPoints(array(1700,2500,7800,5),"Distance");
$MyData->setAxisName(0,"Maximum distance");
$MyData->setAxisUnit(0,"m");
$MyData->setAxisDisplay(0,AXIS_FORMAT_METRIC);
$MyData->setAxisName(0,$unit);
$MyData->addPoints(array(1526886033000, 1526893630000, 1526972433000, 1526972433300),"Timestamp");
$MyData->setSerieDescription("Timestamp", $xaxisname);
$MyData->setAbscissa("Timestamp");
$MyData->setXAxisDisplay(AXIS_FORMAT_DATE);
*/
// Create the pChart object
//$myPicture = new pImage(800, 800, $MyData);
/*
$myPicture->setGraphArea(60,60,660,190);
$myPicture->drawText(350,55,"My chart title",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
$myPicture->drawFilledRectangle(60,60,660,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
*/
/*
$myPicture->setGraphArea(60,60,800,400);
$myPicture->drawText(350,55,"My chart title",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
$myPicture->drawFilledRectangle(60,60,800,400,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
$myPicture->drawScale(array("DrawSubTicks"=>TRUE,"LabelShowBoundaries"=>TRUE,"ScaleModeAuto"=>TRUE));
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
$myPicture->setFontProperties(array("FontName"=>"fonts/pf_arma_five.ttf","FontSize"=>6));
$myPicture->drawStepChart(array("DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO,"ScaleModeAuto"=>TRUE));
$myPicture->drawAreaChart(array("DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO));
//$myPicture->setShadow(FALSE);
*/
/* Create and populate the pData object */ /* Create and populate the pData object */
$MyData = new pData(); $MyData = new pData();
$MyData->addPoints(array(-4,VOID,VOID,12,8,3),"Probe 1"); $MyData->addPoints(array(20,22,25,5,12,8,30,8),"Probe 1");
$MyData->addPoints(array(3,12,15,8,5,-5),"Probe 2"); //$MyData->addPoints(array(3,12,15,8,8,5,-5),"Probe 2");
$MyData->addPoints(array(2,7,5,18,19,22),"Probe 3");
$MyData->setSerieTicks("Probe 2",4); $MyData->setSerieTicks("Probe 2",4);
$MyData->setAxisName(0,"Temperatures"); $MyData->setAxisName(0,"Temperatures");
$MyData->addPoints(array(1296299019,1296302903,1296307001,1296308071,1296309901,1296318931),"Labels"); $MyData->addPoints(array(1296299019,1296302903,1296307001,1296308071,1296309901,1296318931, 1296318941, 1296318942,1296338941),"Labels");
$MyData->setSerieDescription("Labels","Timestamp"); $MyData->setSerieDescription("Labels","Timestamp");
$MyData->setXAxisDisplay(AXIS_FORMAT_DATE,"H:i"); $MyData->setXAxisDisplay(AXIS_FORMAT_DATE,"H:i");
$MyData->setAbscissa("Labels"); $MyData->setAbscissa("Labels");
@ -1021,7 +903,7 @@ $MyData->setAbscissa("Labels");
$myPicture = new pImage(700,230,$MyData); $myPicture = new pImage(700,230,$MyData);
/* Draw the background */ /* Draw the background */
$Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107); $Settings = array("R"=>170, "G"=>183, "B"=>87);
$myPicture->drawFilledRectangle(0,0,700,230,$Settings); $myPicture->drawFilledRectangle(0,0,700,230,$Settings);
/* Overlay with a gradient */ /* Overlay with a gradient */
@ -1046,65 +928,94 @@ $myPicture->drawFilledRectangle(60,60,450,190,array("R"=>255,"G"=>255,"B"=>255,"
$myPicture->drawScale(array("DrawSubTicks"=>TRUE,"LabelShowBoundaries"=>TRUE,"ScaleModeAuto"=>TRUE)); $myPicture->drawScale(array("DrawSubTicks"=>TRUE,"LabelShowBoundaries"=>TRUE,"ScaleModeAuto"=>TRUE));
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
$myPicture->setFontProperties(array("FontName" =>$font, "FontSize" => $font_size)); $myPicture->setFontProperties(array("FontName" =>$font, "FontSize" => $font_size));
$myPicture->drawStepChart(array("DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO,"ScaleModeAuto"=>TRUE)); $myPicture->drawAreaChart(array("BreakVoid"=>FALSE, "BreakR"=>234, "BreakG"=>55, "BreakB"=>26, "DisplayValues"=>FALSE,"DisplayColor"=>DISPLAY_AUTO,"ScaleModeAuto"=>TRUE));
$myPicture->setShadow(FALSE);
/* Draw the scale and the 2nd chart */
$myPicture->setGraphArea(500,60,670,190);
$myPicture->drawFilledRectangle(500,60,670,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
$myPicture->drawScale(array("Pos"=>SCALE_POS_TOPBOTTOM,"DrawSubTicks"=>TRUE,"ScaleModeAuto"=>TRUE));
$myPicture->setShadow(TRUE,array("X"=>-1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
$myPicture->drawStepChart(array("ScaleModeAuto"=>TRUE));
$myPicture->setShadow(FALSE); $myPicture->setShadow(FALSE);
/* Write the chart legend */ /* Write the chart legend */
$myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); $myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
/* Render the picture (choose the best way) */
//$myPicture->autoOutput("pictures/example.drawStepChart.png");
$myPicture->stroke(); $myPicture->stroke();
/* /*
// CAT:Vertical Charts
if (!is_array($legend) || empty($legend)) {
unset($legend);
}
if (is_array(reset($data))) {
$data2 = array();
foreach ($data as $i =>$values) {
$c = 0;
foreach ($values as $i2 => $value) {
$data2[$i2][$i] = $value;
$c++;
}
}
$data = $data2;
}
else {
$data = array($data);
}
// Create and populate the pData object
$MyData = new pData();
foreach ($data as $i => $values) {
if (isset($legend)) {
$point_id = $legend[$i];
// Translate the id of serie to legend of id
if (!empty($series_type)) {
if (!isset($series_type[$point_id])) {
$series_type[$point_id] = $series_type[$i];
unset($series_type[$i]);
}
}
}
else {
$point_id = $i;
}
$MyData->addPoints($values, $point_id);
if (!empty($rgb_color)) {
$MyData->setPalette($point_id,
array(
"R" => $rgb_color[$i]['color']["R"],
"G" => $rgb_color[$i]['color']["G"],
"B" => $rgb_color[$i]['color']["B"],
"BorderR" => $rgb_color[$i]['border']["R"],
"BorderG" => $rgb_color[$i]['border']["G"],
"BorderB" => $rgb_color[$i]['border']["B"],
"Alpha" => $rgb_color[$i]['alpha']));
$palette_color = array();
if (isset($rgb_color[$i]['color'])) {
$palette_color["R"] = $rgb_color[$i]['color']["R"];
$palette_color["G"] = $rgb_color[$i]['color']["G"];
$palette_color["B"] = $rgb_color[$i]['color']["B"];
}
if (isset($rgb_color[$i]['color'])) {
$palette_color["BorderR"] = $rgb_color[$i]['border']["R"];
$palette_color["BorderG"] = $rgb_color[$i]['border']["G"];
$palette_color["BorderB"] = $rgb_color[$i]['border']["B"];
}
if (isset($rgb_color[$i]['color'])) {
$palette_color["Alpha"] = $rgb_color[$i]['Alpha'];
}
$MyData->setPalette($point_id, $palette_color);
}
// The weight of the line is not calculated in pixels, so it needs to be transformed
$reduction_coefficient = 0.31;
$MyData->setSerieWeight($point_id, $config['custom_graph_width'] * $reduction_coefficient);
}
$MyData->setAxisName(0,$unit);
$MyData->addPoints($index,"Xaxis");
$MyData->setSerieDescription("Xaxis", $xaxisname);
$MyData->setAbscissa("Xaxis");
$MyData->setAxisDisplay(0, AXIS_FORMAT_TWO_SIGNIFICANT, 0);
switch ($backgroundColor) { switch ($backgroundColor) {
case 'white': case 'white':
$transparent = false; $transparent = false;
@ -1121,7 +1032,6 @@ $myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HOR
$fontColor = array('R' => 200, 'G' => 200, 'B' => 200); $fontColor = array('R' => 200, 'G' => 200, 'B' => 200);
break; break;
} }
//Create the pChart object //Create the pChart object
$myPicture = new pImage($width, $height + $font_size, $MyData, $transparent, $myPicture = new pImage($width, $height + $font_size, $MyData, $transparent,
$backgroundColor, $fontColor); $backgroundColor, $fontColor);
@ -1131,6 +1041,7 @@ $myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HOR
// Add a border to the picture // Add a border to the picture
//$myPicture->drawRectangle(0,0,$width,$height,array("R"=>0,"G"=>0,"B"=>0)); //$myPicture->drawRectangle(0,0,$width,$height,array("R"=>0,"G"=>0,"B"=>0));
//Set the default font //Set the default font
$myPicture->setFontProperties( $myPicture->setFontProperties(
array("FontName" =>$font, "FontSize" => $font_size)); array("FontName" =>$font, "FontSize" => $font_size));
@ -1138,7 +1049,6 @@ $myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HOR
// By default, set a top margin of 5 px // By default, set a top margin of 5 px
$top_margin = 5; $top_margin = 5;
if (isset($legend)) { if (isset($legend)) {
//Set horizontal legend if is posible //Set horizontal legend if is posible
$legend_mode = LEGEND_HORIZONTAL; $legend_mode = LEGEND_HORIZONTAL;
$size = $myPicture->getLegendSize( $size = $myPicture->getLegendSize(
@ -1152,7 +1062,6 @@ $myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HOR
$top_margin = $size['Height']; $top_margin = $size['Height'];
//Write the chart legend //Write the chart legend
$myPicture->drawLegend($width - $size['Width'], 8, $myPicture->drawLegend($width - $size['Width'], 8,
array("Style" => LEGEND_NOBORDER, "Mode" => $legend_mode)); array("Style" => LEGEND_NOBORDER, "Mode" => $legend_mode));
} }
@ -1219,7 +1128,6 @@ $myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HOR
$chart_margin = 36; $chart_margin = 36;
//Area depends on yaxisname //Area depends on yaxisname
if ($yaxisname != '') { if ($yaxisname != '') {
$chart_margin += $chart_size; $chart_margin += $chart_size;
} }
@ -1501,7 +1409,6 @@ $myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HOR
"Surrounding" => 5, "Surrounding" => 5,
"AroundZero" => TRUE); "AroundZero" => TRUE);
if (empty($series_type)) { if (empty($series_type)) {
switch($graph_type) { switch($graph_type) {
case "stacked_area": case "stacked_area":