function generate_graph_image($outputfile)
 {
     // Create Graph Dataset and set axis attributes
     $graphData = new pData();
     $graphData->setAxisName(0, $this->ytitle_actual);
     $graphData->addPoints($this->xlabels, "xaxis");
     $graphData->setSerieDescription("xaxis", "xaxis");
     $graphData->setAbscissa("xaxis");
     $graphData->setXAxisName("ooo");
     // Add each series of plot values to dataset, but Reportico will
     // duplicate series were the same data are displayed in different forms
     // so only add each unique series once
     $seriesadded = array();
     foreach ($this->plot as $k => $v) {
         $series = $v["name"] . $k;
         $graphData->addPoints($v["data"], $series);
         $graphData->setSerieDescription($series, $v["legend"]);
     }
     /*
     $graph->xgrid->SetColor($this->xgridcolor);
     $graph->ygrid->SetColor($this->ygridcolor);
     */
     /*
     switch ( $this->xgriddisplay )
     {
     	case "all":
     		$graph->xgrid->Show(true,true);
     		break;
     	case "major":
     		$graph->xgrid->Show(true,false);
     		break;
     	case "minor":
     		$graph->xgrid->Show(false,true);
     		break;
     	case "none":
     	default:
     		$graph->xgrid->Show(false,false);
     		break;
     }
     
     switch ( $this->ygriddisplay )
     {
     	case "all":
     		$graph->ygrid->Show(true,true);
     		break;
     	case "major":
     		$graph->ygrid->Show(true,false);
     		break;
     	case "minor":
     		$graph->ygrid->Show(false,true);
     		break;
     	case "none":
     	default:
     		$graph->ygrid->Show(false,false);
     		break;
     }
     */
     /*
     $graph->xaxis->SetFont($fontfamilies[$xaxisfont],$fontstyles[$xaxisfontstyle], $xaxisfontsize);
     $graph->xaxis->SetColor($xaxiscolor,$xaxisfontcolor);
     $graph->yaxis->SetFont($fontfamilies[$yaxisfont],$fontstyles[$yaxisfontstyle], $yaxisfontsize);
     $graph->yaxis->SetColor($yaxiscolor,$yaxisfontcolor);
     $graph->xaxis->title->SetFont($fontfamilies[$xtitlefont],$fontstyles[$xtitlefontstyle], $xtitlefontsize);
     $graph->xaxis->title->SetColor($xtitlecolor);
     $graph->yaxis->title->SetFont($fontfamilies[$ytitlefont],$fontstyles[$ytitlefontstyle], $ytitlefontsize);
     $graph->yaxis->title->SetColor($ytitlecolor);
     $graph->xaxis->SetLabelAngle(90);
     $graph->xaxis->SetLabelMargin(15); 
     $graph->yaxis->SetLabelMargin(15); 
     $graph->xaxis->SetTickLabels($xlabels);
     $graph->xaxis->SetTextLabelInterval($xticklabint);
     $graph->yaxis->SetTextLabelInterval($yticklabint);
     $graph->xaxis->SetTextTickInterval($xtickinterval);
     $graph->yaxis->SetTextTickInterval($ytickinterval);
     */
     /*
     if ( $gridpos == "front" )
     	$graph->SetGridDepth(DEPTH_FRONT); 
     */
     // Display the graph
     /*?$graph->Stroke();*/
     $this->apply_defaults_internal();
     //echo "oo<BR>";
     //echo "<PRE>";
     //var_dump($graphData);
     //echo $this->width."<BR>";
     //echo $this->height_actual."<BR>";
     $graphImage = new pImage($this->width_actual, $this->height_actual, $graphData);
     /* Turn of Antialiasing */
     $graphImage->Antialias = TRUE;
     // Add gradient fill from chosen background color to white
     $startgradient = $this->htmltorgb("#ffffff");
     $color = $this->htmltorgb($this->graphcolor);
     $graphImage->drawGradientArea(0, 0, $this->width_actual, $this->height_actual, DIRECTION_VERTICAL, array("StartR" => $startgradient[0], "StartG" => $startgradient[1], "StartB" => $startgradient[2], "EndR" => $color[0], "EndG" => $color[1], "EndB" => $color[2], "Alpha" => 100));
     /* Add a border to the picture */
     $graphImage->drawRectangle(0, 0, $this->width_actual - 1, $this->height_actual - 1, array("R" => 200, "G" => 200, "B" => 200));
     /* Set the title font and draw it */
     $graphImage->setFontProperties(array("FontName" => PCHARTFONTS_DIR . $this->titlefont, "FontSize" => $this->titlefontsize));
     $this->titlecolor = $this->htmltorgb($this->titlecolor);
     $graphImage->drawText(20, 30, $this->title_actual, array("R" => $this->titlecolor[0], "G" => $this->titlecolor[1], "B" => $this->titlecolor[2]));
     /* Set the default font from the X title font */
     $graphImage->setFontProperties(array("FontName" => PCHARTFONTS_DIR . $this->xtitlefont, "FontSize" => $this->xtitlefontsize));
     /* Define the chart area */
     $graphImage->setGraphArea($this->marginleft, $this->margintop, $this->width_actual - $this->marginright, $this->height_actual - $this->marginbottom);
     //$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE,"LabelRotation"=>30);
     //$graphImage->drawScale($scaleSettings);
     //$settings = array("Surrounding"=>-30,"InnerSurrounding"=>30);
     //$graphImage->drawBarChart($settings);
     //$graphImage->autoOutput("pictures/example.drawBarChart.simple.png");
     //return;
     // Before plotting a series ensure they are all not drawable.
     /// Plot the chart data
     $stackeddrawn = false;
     $stackedexists = false;
     $barexists = false;
     foreach ($this->plot as $k => $v) {
         if ($v["type"] == "STACKEDBAR") {
             $stackedexists = true;
         }
         if ($v["type"] == "STACKEDBAR" || $v["type"] == "BAR") {
             $barexists = true;
         }
     }
     /* Draw the scale */
     $scaleSettings = array("GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE, "LabelRotation" => 30);
     // For stacked charts fix up the Max and Min values;
     if ($stackedexists) {
         $scaleMin = "Unknown";
         $scaleMax = 0;
         foreach ($this->plot as $k => $v) {
             if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") {
                 $series = $v["name"] . $k;
                 $min = $graphData->getMin($series);
                 if ($scaleMin == "Unknown" || $min < $scaleMin) {
                     $scaleMin = $min;
                 }
                 $scaleMax = $scaleMax + $graphData->getMax($series);
             }
         }
         if ($scaleMin > 0) {
             $scaleMin = 0;
         }
         $range = $scaleMax - $scaleMin;
         // Make scales based on 5% of the range of values
         $scaleMax = round($range * 0.05 + $scaleMax);
         if ($scaleMin < 0) {
             $scaleMin = $scaleMin - round($range * 0.05);
         }
         $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax));
         $scaleSettings["Mode"] = SCALE_MODE_MANUAL;
         $scaleSettings["ManualScale"] = $AxisBoundaries;
     } else {
         if ($barexists) {
             $scaleMin = "Unknown";
             $scaleMax = 0;
             foreach ($this->plot as $k => $v) {
                 if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") {
                     $series = $v["name"] . $k;
                     $min = $graphData->getMin($series);
                     if ($scaleMin == "Unknown" || $min < $scaleMin) {
                         $scaleMin = $min;
                     }
                     $max = $graphData->getMax($series);
                     if ($scaleMax == "Unknown" || $max > $scaleMax) {
                         $scaleMax = $max;
                     }
                 }
             }
             if ($scaleMin > 0) {
                 $scaleMin = 0;
             }
             $range = $scaleMax - $scaleMin;
             // Make scales based on 5% of the range of values
             $scaleMax = round($range * 0.05 + $scaleMax);
             if ($scaleMin < 0) {
                 $scaleMin = $scaleMin - round($range * 0.05);
             }
             $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax));
             $scaleSettings["Mode"] = SCALE_MODE_MANUAL;
             $scaleSettings["ManualScale"] = $AxisBoundaries;
         }
     }
     $graphImage->drawScale($scaleSettings);
     // If there's a Pie chart we want to draw different legends
     $piechart = false;
     foreach ($this->plot as $k => $v) {
         foreach ($this->plot as $k1 => $v1) {
             $series = $v1["name"] . $k1;
             $graphData->setSerieDrawable($series, FALSE);
         }
         $series = $v["name"] . $k;
         $graphData->setSerieDrawable($series, TRUE);
         switch ($v["type"]) {
             case "PIE":
                 $piechart = true;
                 $pie = new pPie($graphImage, $graphData);
                 //$pie->draw2DPie($width_actual / 2,$height_actual / 2,80,array("DrawLabels"=>TRUE,"LabelStacked"=>TRUE,"Border"=>TRUE));
                 $pie->draw2DPie($width_actual / 2, $height_actual / 2, 80, array("WriteValues" => PIE_VALUE_PERCENTAGE, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => TRUE, "BorderR" => 255, "BorderG" => 255, "BorderB" => 255));
                 break;
             case "PIE3D":
                 $piechart = true;
                 $pie = new pPie($graphImage, $graphData);
                 $pie->draw3DPie($this->width_actual / 2, $this->height_actual / 2, 80, array("SecondPass" => FALSE));
                 break;
             case "STACKEDBAR":
             case "BAR":
                 if ($stackeddrawn) {
                     break;
                 }
                 if ($barexists) {
                     foreach ($this->plot as $k1 => $v1) {
                         if ($v1["type"] == "BAR" || $v1["type"] == "STACKEDBAR") {
                             $graphData->setSerieDrawable($v1["name"] . $k1, TRUE);
                         }
                     }
                 }
                 $stackeddrawn = true;
                 $settings = array("Surrounding" => -30, "InnerSurrounding" => 30);
                 if ($stackedexists) {
                     $graphImage->drawStackedBarChart($settings);
                 } else {
                     $graphImage->drawBarChart($settings);
                 }
                 break;
             case "LINE":
             default:
                 if (count($v["data"]) == 1) {
                     $v["data"][] = 0;
                 }
                 $graphImage->drawLineChart($settings);
                 break;
         }
     }
     $graphData->drawAll();
     if ($piechart) {
         $pie->drawPieLegend($this->width_actual - 100, 30, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL));
     } else {
         $graphImage->drawLegend($this->width_actual - 180, 22, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL));
     }
     $graphImage->setShadow(TRUE, array("X" => 0, "Y" => 0, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
     $graphImage->render($outputfile);
     return true;
 }
示例#2
0
 function generate_graph_image($outputfile)
 {
     // Create Graph Dataset and set axis attributes
     $graphData = new pData();
     $graphData->setYAxisName($this->ytitle);
     $graphData->AddPoint($this->xlabels, "xaxis");
     //$graphData->SetSerieName("xaxis","xaxis");
     $graphData->SetAbsciseLabelSerie("xaxis");
     $graphData->setXAxisName($this->xtitle);
     // Add each series of plot values to dataset, but Reportico will
     // duplicate series were the same data are displayed in different forms
     // so only add each unique series once
     $seriesadded = array();
     foreach ($this->plot as $k => $v) {
         $series = $v["name"] . $k;
         $graphData->AddPoint($v["data"], $series);
         $graphData->SetSerieName($v["legend"], $series);
         $graphData->AddSerie($series);
     }
     /*
     switch ( $this->xgriddisplay )
     {
     	case "all":
     		$graph->xgrid->Show(true,true);
     		break;
     	case "major":
     		$graph->xgrid->Show(true,false);
     		break;
     	case "minor":
     		$graph->xgrid->Show(false,true);
     		break;
     	case "none":
     	default:
     		$graph->xgrid->Show(false,false);
     		break;
     }
     
     switch ( $this->ygriddisplay )
     {
     	case "all":
     		$graph->ygrid->Show(true,true);
     		break;
     	case "major":
     		$graph->ygrid->Show(true,false);
     		break;
     	case "minor":
     		$graph->ygrid->Show(false,true);
     		break;
     	case "none":
     	default:
     		$graph->ygrid->Show(false,false);
     		break;
     }
     */
     /*
     $graph->xaxis->SetFont($fontfamilies[$xaxisfont],$fontstyles[$xaxisfontstyle], $xaxisfontsize);
     $graph->xaxis->SetColor($xaxiscolor,$xaxisfontcolor);
     $graph->yaxis->SetFont($fontfamilies[$yaxisfont],$fontstyles[$yaxisfontstyle], $yaxisfontsize);
     $graph->yaxis->SetColor($yaxiscolor,$yaxisfontcolor);
     $graph->xaxis->title->SetFont($fontfamilies[$xtitlefont],$fontstyles[$xtitlefontstyle], $xtitlefontsize);
     $graph->xaxis->title->SetColor($xtitlecolor);
     $graph->yaxis->title->SetFont($fontfamilies[$ytitlefont],$fontstyles[$ytitlefontstyle], $ytitlefontsize);
     $graph->yaxis->title->SetColor($ytitlecolor);
     $graph->xaxis->SetLabelAngle(90);
     $graph->xaxis->SetLabelMargin(15); 
     $graph->yaxis->SetLabelMargin(15); 
     $graph->xaxis->SetTickLabels($this->xlabels);
     $graph->xaxis->SetTextLabelInterval($xticklabint);
     $graph->yaxis->SetTextLabelInterval($yticklabint);
     $graph->xaxis->SetTextTickInterval($xtickinterval);
     $graph->yaxis->SetTextTickInterval($ytickinterval);
     */
     /*
     if ( $gridpos == "front" )
     	$graph->SetGridDepth(DEPTH_FRONT); 
     */
     // Display the graph
     /*?$graph->Stroke();*/
     $this->apply_defaults_internal();
     //echo $this->width_pdf_actual.",".$this->height_pdf_actual."<BR>";
     $graphImage = new pChart($this->width_pdf_actual, $this->height_pdf_actual);
     /* Turn of Antialiasing */
     $graphImage->Antialias = TRUE;
     // Add gradient fill from chosen background color to white
     $startgradient = htmltorgb("#ffffff");
     //$graphImage->drawGradientArea(0,0,$width,$height,DIRECTION_VERTICAL,array(
     //"StartR"=>$startgradient[0], "StartG"=>$startgradient[1], "StartB"=>$startgradient[2],
     //"EndR"=>$color[0], "EndG"=>$color[1], "EndB"=>$color[2],"Alpha"=>100));
     /* Add a border to the picture */
     //$graphImage->drawRectangle(0,0,$width - 1,$height - 1,200,200,200);
     $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xaxisfont, $this->xaxisfontsize);
     /* Define the chart area */
     $graphImage->setGraphArea($this->marginleft_actual, $this->margintop_actual, $this->width_pdf_actual - $this->marginright_actual, $this->height_pdf_actual - $this->marginbottom_actual);
     $graphImage->drawFilledRoundedRectangle(3, 3, $this->width_pdf_actual - 3, $this->height_pdf_actual - 3, 5, 240, 240, 240);
     $graphImage->drawRoundedRectangle(1, 1, $this->width_pdf_actual - 1, $this->height_pdf_actual - 1, 5, 230, 230, 230);
     // Before plotting a series ensure they are all not drawable.
     /// Plot the chart data
     $stackeddrawn = false;
     $linedrawn = false;
     $scatterdrawn = false;
     $piedrawn = false;
     $stackedexists = false;
     $overlayexists = false;
     $barexists = false;
     foreach ($this->plot as $k => $v) {
         if ($v["type"] == "OVERLAYBAR") {
             $overlayexists = true;
         }
         if ($v["type"] == "STACKEDBAR") {
             $stackedexists = true;
         }
         if ($v["type"] == "STACKEDBAR" || $v["type"] == "BAR") {
             $barexists = true;
         }
         // Set plot colors
         if ($v["linecolor"]) {
             $graphImage->Palette[$k] = htmltorgb_pchart($v["linecolor"]);
         }
         $url .= "&plotlinecolor{$k}=" . $v["linecolor"];
     }
     $scale_drawing_mode = SCALE_NORMAL;
     $scale_drawing_mode = SCALE_START0;
     // For stacked charts fix up the Max and Min values;
     if ($stackedexists) {
         $scale_drawing_mode = SCALE_ADDALL;
         $scaleMin = "Unknown";
         $scaleMax = 0;
         $min = false;
         $max = false;
         foreach ($plot as $k => $v) {
             if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") {
                 $series = $v["name"] . $k;
                 minmaxValueOfSeries($v["data"], $min, $max);
                 if ($scaleMin == "Unknown" || $min < $scaleMin) {
                     $scaleMin = $min;
                 }
                 $scaleMax = $scaleMax + $max;
             }
         }
         if ($scaleMin > 0) {
             $scaleMin = 0;
         }
         $range = $scaleMax - $scaleMin;
         // Make scales based on 5% of the range of values
         $scaleMax = round($range * 0.05 + $scaleMax);
         if ($scaleMin < 0) {
             $scaleMin = $scaleMin - round($range * 0.05);
         }
         $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax));
     } else {
         if ($barexists || $overlayexists) {
             $scaleMin = "Unknown";
             $scaleMax = 0;
             $min = false;
             $max = false;
             foreach ($this->plot as $k => $v) {
                 if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") {
                     $series = $v["name"] . $k;
                     minmaxValueOfSeries($v["data"], $min, $max);
                     if ($scaleMin == "Unknown" || $min < $scaleMin) {
                         $scaleMin = $min;
                     }
                     if ($scaleMax == "Unknown" || $max > $scaleMax) {
                         $scaleMax = $max;
                     }
                 }
             }
             if ($scaleMin > 0) {
                 $scaleMin = 0;
             }
             $range = $scaleMax - $scaleMin;
             // Make scales based on 5% of the range of values
             $scaleMax = round($range * 0.05 + $scaleMax);
             if ($scaleMin < 0) {
                 $scaleMin = $scaleMin - round($range * 0.05);
             }
             $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax));
         }
     }
     //echo "<PRE>";
     //var_dump($graphData->GetDataDescription());
     //die;
     // Find out if a scale is required, will be except for pie charts
     $scalerequired = false;
     foreach ($this->plot as $k => $v) {
         switch ($v["type"]) {
             case "BAR":
             case "STACKEDBAR":
             case "OVERLAYBAR":
             case "LINE":
                 $scalerequired = "NORMAL";
                 break;
             case "SCATTER":
                 $scalerequired = "SCATTER";
                 break;
         }
     }
     $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xtitlefont, $this->xtitlefontsize);
     if ($scalerequired) {
         $graphImage->setGraphArea($this->marginleft_actual, $this->margintop_actual, $this->width_pdf_actual - $this->marginright, $this->height_pdf_actual - $this->marginbottom_actual);
         $graphImage->drawGraphAreaGradient(240, 240, 240, -20);
         // Automatic generation of x tick interval based on number of ticks
         if ($this->xticklabelinterval_actual == "AUTO") {
             $labct = count($this->plot[0]["data"]);
             $this->xticklabelinterval_actual = floor($labct / 35) + 1;
         }
         if ($scalerequired == "NORMAL") {
             $graphImage->drawScale($graphData->GetData(), $graphData->GetDataDescription(), $scale_drawing_mode, 0, 0, 0, TRUE, 40, FALSE, TRUE, $this->xticklabelinterval_actual, FALSE);
         }
         $graphImage->drawGrid(2, TRUE, 230, 230, 230, 45);
     } else {
         $this->marginright = 5;
         $this->marginbottom = 5;
         $this->marginleft = 5;
         $this->marginright_actual = 5;
         $this->marginbottom_actual = 5;
         $this->marginleft_actual = 5;
         //$this->margintop_actual = 5;
         $graphImage->setGraphArea($this->marginleft, $this->margintop_actual, $this->width_pdf_actual - $this->marginright, $this->height_pdf_actual - $this->marginbottom);
         $graphImage->drawGraphAreaGradient(240, 240, 240, -10);
     }
     // If there's a Pie chart we want to draw different legends
     $piechart = false;
     foreach ($this->plot as $k => $v) {
         disableAllSeries($this->plot, $graphData);
         $series = $v["name"] . $k;
         setSerieDrawable($this->plot, $graphData, $series, TRUE);
         switch ($v["type"]) {
             case "PIE":
                 $piedrawn = true;
                 $piechart = true;
                 $graphImage->drawFilledCircle($this->width_pdf_actual / 2 + 2, $this->margintop_actual + 2 + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.45 + 1, 200, 200, 200);
                 $graphImage->drawBasicPieGraph($graphData->GetData(), $graphData->GetDataDescription(), $this->width_pdf_actual / 2, $this->margintop_actual + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.45, PIE_PERCENTAGE_LABEL, 255, 255, 218);
                 break;
             case "PIE3D":
                 $piedrawn = true;
                 $piechart = true;
                 $graphImage->drawPieGraph($graphData->GetData(), $graphData->GetDataDescription(), $this->width_pdf_actual / 2, $this->margintop_actual + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.5, PIE_PERCENTAGE_LABEL, true, 60, 20, 0, 0);
                 break;
             case "OVERLAYBAR":
             case "STACKEDBAR":
             case "BAR":
                 if ($stackeddrawn) {
                     break;
                 }
                 if ($barexists || $overlayexists) {
                     foreach ($this->plot as $k1 => $v1) {
                         if ($v1["type"] == "BAR" || $v1["type"] == "STACKEDBAR" || $v1["type"] == "OVERLAYBAR") {
                             setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE);
                         }
                     }
                 }
                 $stackeddrawn = true;
                 if ($stackedexists) {
                     $graphImage->drawStackedBarGraph($graphData->GetData(), $graphData->GetDataDescription(), 90);
                 } else {
                     if ($overlayexists) {
                         $graphImage->drawOverlayBarGraph($graphData->GetData(), $graphData->GetDataDescription(), 90);
                     } else {
                         $graphImage->drawBarGraph($graphData->GetData(), $graphData->GetDataDescription());
                     }
                 }
                 break;
             case "SCATTER":
                 if ($scatterdrawn) {
                     break;
                 }
                 $scatterdrawn = true;
                 $series1 = false;
                 $series2 = false;
                 $graphImage->reportWarnings("GD");
                 $ct = 0;
                 foreach ($this->plot as $k1 => $v1) {
                     if ($v1["type"] == "SCATTER") {
                         if ($ct == 0) {
                             $series1 = $v1["name"] . $k1;
                         }
                         if ($ct == 1) {
                             $series2 = $v1["name"] . $k1;
                         }
                         $ct++;
                         setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE);
                     }
                 }
                 if (count($v["data"]) == 1) {
                     $v["data"][] = 0;
                 }
                 $graphImage->drawXYScale($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2, 0, 0, 0);
                 //$graphImage->drawXYGraph($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2);
                 $graphImage->drawXYPlotGraph($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2);
                 $graphImage->writeValues($graphData->GetData(), $graphData->GetDataDescription(), $series2);
                 break;
             case "LINE":
             default:
                 if ($linedrawn) {
                     break;
                 }
                 $linedrawn = true;
                 foreach ($this->plot as $k1 => $v1) {
                     if ($v1["type"] == "LINE") {
                         setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE);
                     }
                 }
                 if (count($v["data"]) == 1) {
                     $v["data"][] = 0;
                 }
                 $graphImage->LineWidth = 1;
                 $graphImage->drawLineGraph($graphData->GetData(), $graphData->GetDataDescription());
                 $graphImage->drawPlotGraph($graphData->GetData(), $graphData->GetDataDescription());
                 $graphImage->LineWidth = 1;
                 break;
         }
     }
     foreach ($this->plot as $k1 => $v1) {
         setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE);
     }
     // Draw Legend if legend value has been set
     $drawlegend = false;
     foreach ($this->plot as $k => $v) {
         if (isset($v["legend"]) && $v["legend"]) {
             // Temporarily Dont draw legend for Pie
             //if ( $piechart )
             //$graphImage->drawPieLegend($this->width_pdf_actual - 180,30,$graphData->GetData(), $graphData->GetDataDescription(), 250, 250, 250);
             if (!$piechart) {
                 $graphImage->drawLegend($this->width_pdf_actual - 120, 30, $graphData->GetDataDescription(), 254, 254, 254, 0, 0, 0);
             }
             break;
         }
     }
     $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xtitlefont, $this->titlefontsize);
     $graphImage->drawTitle(0, 24, $this->title_actual, 50, 50, 50, $this->width_pdf_actual);
     //$graphImage->setShadow(TRUE,array("X"=>0,"Y"=>0,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
     //$graphImage->Render("example.png");
     //$graphImage->Stroke();
     $graphImage->render($outputfile);
     return true;
 }
	$graph->SetMarginColor($margincolor);
	$graph->img->SetAntiAliasing(); 
	$graph->SetColor($color);
	$graph->SetShadow();
	$graph->xaxis->SetTitleMargin($marginbottom - 35); 
	$graph->yaxis->SetTitleMargin(50);
	$graph->yaxis->SetTitleMargin($marginleft - 15); 
}
*/
// Create Graph Dataset and set axis attributes
$graphData = new pData();
$graphData->setYAxisName($ytitle);
$graphData->AddPoint($xlabels, "xaxis");
//$graphData->SetSerieName("xaxis","xaxis");
$graphData->SetAbsciseLabelSerie("xaxis");
$graphData->setXAxisName($xtitle);
// Add each series of plot values to dataset, but Reportico will
// duplicate series were the same data are displayed in different forms
// so only add each unique series once
$seriesadded = array();
foreach ($plot as $k => $v) {
    $series = $v["name"] . $k;
    $graphData->AddPoint($v["data"], $series);
    $graphData->SetSerieName($v["legend"], $series);
    $graphData->AddSerie($series);
}
/*
switch ( $xgriddisplay )
{
	case "all":
		$graph->xgrid->Show(true,true);
 /**
  * Create a history graph for the given info type
  *
  * @param $info
  */
 protected function history($info)
 {
     $diff = abs(strtotime($this->from) - strtotime($this->to));
     $days = floor($diff / (60 * 60 * 24));
     if ($days > 365) {
         $interval = 'months';
     } elseif ($days > 56) {
         $interval = 'weeks';
     } else {
         $interval = 'days';
     }
     $result = $this->hlp->Query()->history($this->tlimit, $info, $interval);
     $data = array();
     $times = array();
     foreach ($result as $row) {
         $data[] = $row['cnt'];
         if ($interval == 'months') {
             $times[] = substr($row['time'], 0, 4) . '-' . substr($row['time'], 4, 2);
         } elseif ($interval == 'weeks') {
             $times[] = $row['EXTRACT(YEAR FROM dt)'] . '-' . $row['time'];
         } else {
             $times[] = substr($row['time'], -5);
         }
     }
     $DataSet = new pData();
     $DataSet->AddPoints($data, 'Serie1');
     $DataSet->AddPoints($times, 'Times');
     $DataSet->AddAllSeries();
     $DataSet->SetAbscissaLabelSeries('Times');
     $DataSet->setXAxisName($this->hlp->getLang($interval));
     $DataSet->setYAxisName($this->hlp->getLang('graph_' . $info));
     $Canvas = new GDCanvas(600, 200, false);
     $Chart = new pChart(600, 200, $Canvas);
     $Chart->setFontProperties(dirname(__FILE__) . '/pchart/Fonts/DroidSans.ttf', 8);
     $Chart->setGraphArea(50, 10, 580, 140);
     $Chart->drawScale($DataSet, new ScaleStyle(SCALE_NORMAL, new Color(127)), 45, 1, false, ceil(count($times) / 12));
     $Chart->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
     $DataSet->removeSeries('Times');
     $DataSet->removeSeriesName('Times');
     header('Content-Type: image/png');
     $Chart->Render('');
 }
示例#5
0
}
/* Close DB Connection */
$db->close();
////////////////////////////////////////////////////////////////
// Organise Data for Graphing
//
/* Load date time data */
$MyData->addPoints($timestamp, "Timestamp");
/* Load Temperature data */
$MyData->addPoints($temperature, "Temperature");
/* Load Humidity data */
$MyData->addPoints($humidity, "Humidity");
/* Set X-Axis */
$MyData->setAbscissa("Timestamp");
/* Set X-Axis name */
$MyData->setXAxisName("Time");
/* Setup Series Y-Axis 0 */
$MyData->setSerieOnAxis("Temperature", 0);
/* Setup Series Y-Axis 1 */
$MyData->setSerieOnAxis("Humidity", 1);
/* Setup Series Y-Axis 1 Location */
$MyData->setAxisPosition(1, AXIS_POSITION_RIGHT);
/* Set Y-Axis Series 0 name */
$MyData->setAxisName(0, "Temperature");
/* Set Y-Axis Series 1 name */
$MyData->setAxisName(1, "Humidity");
/* Set Y-Axis Series 0 Units */
$MyData->setAxisUnit(0, "°C");
/* Set Y-Axis Series 1 Units */
$MyData->setAxisUnit(1, "%");
////////////////////////////////////////////////////////////////
示例#6
0
function electrique_mois()
{
    //initialisation des variables tableau
    $timestamp = "";
    $conso = "";
    $sql = mysql_query("SELECT TIMESTAMP(CONCAT(YEAR(date_histo ),'-',MONTH(date_histo ),'-',DAY(date_histo ),' ',HOUR(date_histo ),':00')),\n\t\t\t\t\tdate_histo, AVG(valeur1),MAX(valeur1),MIN(valeur1)\n\t\t\t\t\tFROM historique_donnees\n\t\t\t\t\tWHERE id_objet = 2\n\t\t\t\t\tAND date_histo >  DATE_SUB(NOW( ), INTERVAL 31 DAY)\n\t\t\t\t\tGROUP BY YEAR( date_histo ) , MONTH( date_histo ) , DAY( date_histo ),  HOUR( date_histo ),  id_objet\n\t\t\t\t\tHAVING HOUR( date_histo ) IN ( 00, 06, 12, 18 ) \n\t\t\t\t\tORDER BY date_histo");
    while (list($date_histo, $date_histo2, $conso_sql, $conso_sql_max, $conso_sql_min) = mysql_fetch_array($sql)) {
        $timestamp[] = strtotime($date_histo);
        $conso[] = $conso_sql;
        $conso_max[] = $conso_sql_max;
        $conso_min[] = $conso_sql_min;
    }
    $myData = new pData();
    $myData->addPoints($timestamp, "Timestamp");
    $myData->addPoints($conso, "Consommation Instantanée Moyenne");
    $myData->addPoints($conso_max, "Conso. Inst. Max");
    $myData->addPoints($conso_min, "Conso. Inst. Min");
    $myData->setSerieOnAxis("Consommation Instantanée", 0);
    $myData->setSerieOnAxis("Conso. Inst. Max", 0);
    $myData->setSerieOnAxis("Conso. Inst. Min", 0);
    $myData->setAbscissa("Timestamp");
    $myData->setXAxisName("Time");
    $myData->setXAxisDisplay(AXIS_FORMAT_TIME, "d/m");
    $myData->setAxisName(0, "Consommation Instantanée");
    $myData->setAxisUnit(0, "W");
    $myPicture = new pImage(1250, 550, $myData);
    $Settings = array("StartR" => 48, "StartG" => 124, "StartB" => 183, "EndR" => 33, "EndG" => 86, "EndB" => 128, "Alpha" => 50);
    $myPicture->drawGradientArea(0, 0, 1250, 550, DIRECTION_VERTICAL, $Settings);
    $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 20));
    $myPicture->setFontProperties(array("FontName" => "fonts/Forgotte.ttf", "FontSize" => 18));
    $TextSettings = array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 255, "G" => 255, "B" => 255);
    $myPicture->drawText(350, 25, "Consommation éléctrique", $TextSettings);
    $myPicture->setShadow(FALSE);
    $myPicture->setGraphArea(110, 50, 1160, 500);
    $myPicture->setFontProperties(array("R" => 0, "G" => 0, "B" => 0, "FontName" => "fonts/Forgotte.ttf", "FontSize" => 14));
    $Settings = array("Pos" => SCALE_POS_LEFTRIGHT, "Mode" => SCALE_MODE_FLOATING, "LabelingMethod" => LABELING_ALL, "GridR" => 255, "GridG" => 255, "GridB" => 255, "GridAlpha" => 50, "TickR" => 0, "TickG" => 0, "TickB" => 0, "TickAlpha" => 50, "LabelRotation" => 45, "CycleBackground" => 1, "DrawXLines" => 1, "DrawSubTicks" => 1, "SubTickR" => 255, "SubTickG" => 0, "SubTickB" => 0, "SubTickAlpha" => 50, "DrawYLines" => ALL, "LabelSkip" => 3);
    $myPicture->drawScale($Settings);
    $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 10));
    $Config = "";
    $myPicture->drawSplineChart($Config);
    $Config = array("FontR" => 0, "FontG" => 0, "FontB" => 0, "FontName" => "fonts/Forgotte.ttf", "FontSize" => 14, "Margin" => 6, "Alpha" => 30, "BoxSize" => 5, "Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL);
    $myPicture->drawLegend(563, 16, $Config);
    $myPicture->render("tmp/graphe_em.png");
    echo "<img src='tmp/graphe_em.png' alt='graphe'/>";
}
	$graph->SetMarginColor($margincolor);
	$graph->img->SetAntiAliasing(); 
	$graph->SetColor($color);
	$graph->SetShadow();
	$graph->xaxis->SetTitleMargin($marginbottom - 35); 
	$graph->yaxis->SetTitleMargin(50);
	$graph->yaxis->SetTitleMargin($marginleft - 15); 
}
*/
// Create Graph Dataset and set axis attributes
$graphData = new pData();
$graphData->setAxisName(0, $ytitle);
$graphData->addPoints($xlabels, "xaxis");
$graphData->setSerieDescription("xaxis", "xaxis");
$graphData->setAbscissa("xaxis");
$graphData->setXAxisName("ooo");
// Add each series of plot values to dataset, but Reportico will
// duplicate series were the same data are displayed in different forms
// so only add each unique series once
$seriesadded = array();
foreach ($plot as $k => $v) {
    $series = $v["name"] . $k;
    $graphData->addPoints($v["data"], $series);
    $graphData->setSerieDescription($series, $v["legend"]);
}
/*
$graph->xgrid->SetColor($xgridcolor);
$graph->ygrid->SetColor($ygridcolor);
*/
/*
switch ( $xgriddisplay )