0

我想用动态数据填充图表,但为了做到这一点,我想将 pchart php 文件嵌入到一个函数中,然后调用它

echo "<img src='grafice();' /> ";

这可能吗?这是我所做的:

function grafice()
{     
/* pChart library inclusions */
include("../class/pData.class.php");
include("../class/pDraw.class.php");
include("../class/pImage.class.php");


/* Create and populate the pData object */

$MyData = new pData();  

$MyData->addPoints(array(10,5,7,8), "Probe 1");


$MyData->setSerieWeight("Probe 1",2);

$MyData->setAxisName(0,"Media Generala");

$MyData->addPoints(array("Ian","Feb","Mar","Apr","Mai","Iun"),"Labels");

$MyData->setSerieDescription("Labels","Luni");

$MyData->setAbscissa("Labels");
 $serieSettings = array("R"=>255,"G"=>185,"B"=>11);
 $MyData->setPalette("Probe 1",$serieSettings);


/* Create the pChart object */

$myPicture = new pImage(500,230,$MyData);



/* Draw the background */

$Settings = array("R"=>248, "G"=>226, "B"=>174, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);

$myPicture->drawFilledRectangle(0,0,700,230,$Settings);



/* Overlay with a gradient */

$Settings = array("StartR"=>238, "StartG"=>216, "StartB"=>174, "EndR"=>238, "EndG"=>216, "EndB"=>174, "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,499,229,array("R"=>0,"G"=>0,"B"=>0));



/* Write the picture title */ 

$myPicture->setFontProperties(array("FontName"=>"../fonts/Silkscreen.ttf","FontSize"=>6));

$myPicture->drawText(10,13,"Evolutia Mediei Generale",array("R"=>255,"G"=>255,"B"=>255));



/* Write the chart title */ 

$myPicture->setFontProperties(array("FontName"=>"../fonts/Forgotte.ttf","FontSize"=>11));

$myPicture->drawText(250,55,"Media Generala",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));



/* Draw the scale and the 1st chart */

$AxisBoundaries = array(0=>array("Min"=>0,"Max"=>10));
$scaleSettings  = array("DrawSubTicks"=>TRUE,"Mode"=>SCALE_MODE_MANUAL, "ManualScale"=>$AxisBoundaries);

$myPicture->setGraphArea(60,60,450,190);

$myPicture->drawFilledRectangle(60,60,450,190,array("R"=>0,"G"=>0,"B"=>0,"Surrounding"=>-200,"Alpha"=>10));

$myPicture->drawScale($scaleSettings);

$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"=>10,"R"=>0,"G"=>0,"B"=>0));

$myPicture->drawLineChart(array("DisplayValues"=>TRUE,"DisplayR"=>0, "DisplayG"=>0, "DisplayB"=>0, "DisplayOffset"=>10));

$myPicture->setShadow(FALSE);




/* Render the picture (choose the best way) */

$myPicture->autoOutput("pictures/example.drawLineChart.png");
}

这甚至可能吗?如果没有,还有其他方法吗?PS我只希望该功能与预定义的点一起使用。我想我会设法向它添加动态数据。

4

1 回答 1

0

我设法做到了,并在这里发布以帮助他人!

所以,我做了这个功能,但我编辑了粗体部分

function grafice()
{     
/* pChart library inclusions */
include("../class/pData.class.php");
include("../class/pDraw.class.php");
include("../class/pImage.class.php");


/* Create and populate the pData object */

$MyData = new pData();  

$MyData->addPoints(array(10,5,7,8), "Probe 1");


$MyData->setSerieWeight("Probe 1",2);

$MyData->setAxisName(0,"Media Generala");

$MyData->addPoints(array("Ian","Feb","Mar","Apr","Mai","Iun"),"Labels");

$MyData->setSerieDescription("Labels","Luni");

$MyData->setAbscissa("Labels");
 $serieSettings = array("R"=>255,"G"=>185,"B"=>11);
 $MyData->setPalette("Probe 1",$serieSettings);


/* Create the pChart object */

$myPicture = new pImage(500,230,$MyData);



/* Draw the background */

$Settings = array("R"=>248, "G"=>226, "B"=>174, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);

$myPicture->drawFilledRectangle(0,0,700,230,$Settings);



/* Overlay with a gradient */

$Settings = array("StartR"=>238, "StartG"=>216, "StartB"=>174, "EndR"=>238, "EndG"=>216, "EndB"=>174, "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,499,229,array("R"=>0,"G"=>0,"B"=>0));



/* Write the picture title */ 

$myPicture->setFontProperties(array("FontName"=>"../fonts/Silkscreen.ttf","FontSize"=>6));

$myPicture->drawText(10,13,"Evolutia Mediei Generale",array("R"=>255,"G"=>255,"B"=>255));



/* Write the chart title */ 

$myPicture->setFontProperties(array("FontName"=>"../fonts/Forgotte.ttf","FontSize"=>11));

$myPicture->drawText(250,55,"Media Generala",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));



/* Draw the scale and the 1st chart */

$AxisBoundaries = array(0=>array("Min"=>0,"Max"=>10));
$scaleSettings  = array("DrawSubTicks"=>TRUE,"Mode"=>SCALE_MODE_MANUAL, "ManualScale"=>$AxisBoundaries);

$myPicture->setGraphArea(60,60,450,190);

$myPicture->drawFilledRectangle(60,60,450,190,array("R"=>0,"G"=>0,"B"=>0,"Surrounding"=>-200,"Alpha"=>10));

$myPicture->drawScale($scaleSettings);

$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"=>10,"R"=>0,"G"=>0,"B"=>0));

$myPicture->drawLineChart(array("DisplayValues"=>TRUE,"DisplayR"=>0, "DisplayG"=>0, "DisplayB"=>0, "DisplayOffset"=>10));

$myPicture->setShadow(FALSE);




/* Render the picture (choose the best way) */

/* $myPicture->**( I DELETED ThIS)--> autoOutput <---** ("pictures/example.drawLineChart.png"); and added */

 $myPicture->render("pictures/example.drawLineChart.png");


}

然后,当我想调用它时,像这样:

<?php grafice(); ?>

然后我可以这样做:

<img src="pictures/example.drawLineChart.png" />

现在我只是用会话 ID 更改图片名称,因此我将为每个人提供不同的图表;)希望这会对某人有所帮助!

于 2013-09-24T12:18:02.453 回答