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,12 +883,67 @@ 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);
html_debug_print($data, true);
/* Create and populate the pData object */
$MyData = new pData();
$MyData->addPoints(array(20,22,25,5,12,8,30,8),"Probe 1");
//$MyData->addPoints(array(3,12,15,8,8,5,-5),"Probe 2");
$MyData->setSerieTicks("Probe 2",4);
$MyData->setAxisName(0,"Temperatures");
$MyData->addPoints(array(1296299019,1296302903,1296307001,1296308071,1296309901,1296318931, 1296318941, 1296318942,1296338941),"Labels");
$MyData->setSerieDescription("Labels","Timestamp");
$MyData->setXAxisDisplay(AXIS_FORMAT_DATE,"H:i");
$MyData->setAbscissa("Labels");
/* Create the pChart object */
$myPicture = new pImage(700,230,$MyData);
/* Draw the background */
$Settings = array("R"=>170, "G"=>183, "B"=>87);
$myPicture->drawFilledRectangle(0,0,700,230,$Settings);
/* Overlay with a gradient */
$Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
$myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,$Settings);
$myPicture->drawGradientArea(0,0,700,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80));
/* Add a border to the picture */
$myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));
/* Write the picture title */
$myPicture->setFontProperties(array("FontName" =>$font, "FontSize" => $font_size));
$myPicture->drawText(10,13,"drawStepChart() - draw a step chart",array("R"=>255,"G"=>255,"B"=>255));
/* Write the chart title */
$myPicture->setFontProperties(array("FontName" =>$font, "FontSize" => $font_size));
$myPicture->drawText(250,55,"Average temperature",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
/* Draw the scale and the 1st chart */
$myPicture->setGraphArea(60,60,450,190);
$myPicture->drawFilledRectangle(60,60,450,190,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" =>$font, "FontSize" => $font_size));
$myPicture->drawAreaChart(array("BreakVoid"=>FALSE, "BreakR"=>234, "BreakG"=>55, "BreakB"=>26, "DisplayValues"=>FALSE,"DisplayColor"=>DISPLAY_AUTO,"ScaleModeAuto"=>TRUE));
$myPicture->setShadow(FALSE);
/* Write the chart legend */
$myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
$myPicture->stroke();
/* /*
// CAT:Vertical Charts
if (!is_array($legend) || empty($legend)) { if (!is_array($legend) || empty($legend)) {
unset($legend); unset($legend);
} }
if (is_array(reset($data))) { if (is_array(reset($data))) {
$data2 = array(); $data2 = array();
foreach ($data as $i =>$values) { foreach ($data as $i =>$values) {
@ -905,15 +958,13 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height,
else { else {
$data = array($data); $data = array($data);
} }
*/
/* Create and populate the pData object */ // Create and populate the pData object
/*
$MyData = new pData(); $MyData = new pData();
foreach ($data as $i => $values) { foreach ($data as $i => $values) {
if (isset($legend)) { if (isset($legend)) {
$point_id = $legend[$i]; $point_id = $legend[$i];
// Translate the id of serie to legend of id // Translate the id of serie to legend of id
if (!empty($series_type)) { if (!empty($series_type)) {
if (!isset($series_type[$point_id])) { if (!isset($series_type[$point_id])) {
@ -928,7 +979,6 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height,
$MyData->addPoints($values, $point_id); $MyData->addPoints($values, $point_id);
if (!empty($rgb_color)) { if (!empty($rgb_color)) {
$MyData->setPalette($point_id, $MyData->setPalette($point_id,
array( array(
@ -939,7 +989,6 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height,
"BorderG" => $rgb_color[$i]['border']["G"], "BorderG" => $rgb_color[$i]['border']["G"],
"BorderB" => $rgb_color[$i]['border']["B"], "BorderB" => $rgb_color[$i]['border']["B"],
"Alpha" => $rgb_color[$i]['alpha'])); "Alpha" => $rgb_color[$i]['alpha']));
$palette_color = array(); $palette_color = array();
if (isset($rgb_color[$i]['color'])) { if (isset($rgb_color[$i]['color'])) {
$palette_color["R"] = $rgb_color[$i]['color']["R"]; $palette_color["R"] = $rgb_color[$i]['color']["R"];
@ -957,154 +1006,16 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height,
$MyData->setPalette($point_id, $palette_color); $MyData->setPalette($point_id, $palette_color);
} }
// The weight of the line is not calculated in pixels, so it needs to be transformed // The weight of the line is not calculated in pixels, so it needs to be transformed
$reduction_coefficient = 0.31; $reduction_coefficient = 0.31;
$MyData->setSerieWeight($point_id, $config['custom_graph_width'] * $reduction_coefficient); $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->setAxisName(0,$unit);
$MyData->addPoints(array(1526886033000, 1526893630000, 1526972433000, 1526972433300),"Timestamp"); $MyData->addPoints($index,"Xaxis");
$MyData->setSerieDescription("Timestamp", $xaxisname); $MyData->setSerieDescription("Xaxis", $xaxisname);
$MyData->setAbscissa("Timestamp"); $MyData->setAbscissa("Xaxis");
$MyData->setXAxisDisplay(AXIS_FORMAT_DATE); $MyData->setAxisDisplay(0, AXIS_FORMAT_TWO_SIGNIFICANT, 0);
*/
// 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 */
$MyData = new pData();
$MyData->addPoints(array(-4,VOID,VOID,12,8,3),"Probe 1");
$MyData->addPoints(array(3,12,15,8,5,-5),"Probe 2");
$MyData->addPoints(array(2,7,5,18,19,22),"Probe 3");
$MyData->setSerieTicks("Probe 2",4);
$MyData->setAxisName(0,"Temperatures");
$MyData->addPoints(array(1296299019,1296302903,1296307001,1296308071,1296309901,1296318931),"Labels");
$MyData->setSerieDescription("Labels","Timestamp");
$MyData->setXAxisDisplay(AXIS_FORMAT_DATE,"H:i");
$MyData->setAbscissa("Labels");
/* Create the pChart object */
$myPicture = new pImage(700,230,$MyData);
/* Draw the background */
$Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
$myPicture->drawFilledRectangle(0,0,700,230,$Settings);
/* Overlay with a gradient */
$Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
$myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,$Settings);
$myPicture->drawGradientArea(0,0,700,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80));
/* Add a border to the picture */
$myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));
/* Write the picture title */
$myPicture->setFontProperties(array("FontName" =>$font, "FontSize" => $font_size));
$myPicture->drawText(10,13,"drawStepChart() - draw a step chart",array("R"=>255,"G"=>255,"B"=>255));
/* Write the chart title */
$myPicture->setFontProperties(array("FontName" =>$font, "FontSize" => $font_size));
$myPicture->drawText(250,55,"Average temperature",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
/* Draw the scale and the 1st chart */
$myPicture->setGraphArea(60,60,450,190);
$myPicture->drawFilledRectangle(60,60,450,190,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" =>$font, "FontSize" => $font_size));
$myPicture->drawStepChart(array("DisplayValues"=>TRUE,"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);
/* Write the chart legend */
$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();
/*
switch ($backgroundColor) { switch ($backgroundColor) {
case 'white': case 'white':
$transparent = false; $transparent = false;
@ -1121,16 +1032,16 @@ $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);
//Turn of Antialiasing // Turn of Antialiasing
$myPicture->Antialias = $antialiasing; $myPicture->Antialias = $antialiasing;
//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;
} }
@ -1353,7 +1261,7 @@ $myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HOR
$ManualScale = array( 0 => array("Min" => $check_scale_min, "Max" => $check_scale) ); $ManualScale = array( 0 => array("Min" => $check_scale_min, "Max" => $check_scale) );
$mode = SCALE_MODE_MANUAL; $mode = SCALE_MODE_MANUAL;
//Draw the scale // Draw the scale
$scaleSettings = array( $scaleSettings = array(
"GridR" => 200, "GridR" => 200,
"GridG" => 200, "GridG" => 200,
@ -1486,7 +1394,7 @@ $myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HOR
break; break;
} }
// Draw the chart //Draw the chart
$settings = array( $settings = array(
"ForceTransparency" => 20, "ForceTransparency" => 20,
"Gradient" => TRUE, "Gradient" => TRUE,
@ -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":