我正在尝试将图表集成到网站中。我通过尝试查看有效的示例来测试 gd2 部分,请参见此处。然后我继续使用以下代码将其集成到我的 php 文件中:
include("grafice/class/pData.class.php");
include("grafice/class/pDraw.class.php");
include("grafice/class/pImage.class.php");
//creaza si populeaza obiectul
$MyData = new pData();
$MyData->addPoints(array(4,VOID,VOID,10,8,3),"Proba 1");
$MyData->addPoints(array(3,10,5,8,5,5),"Proba 2");
$MyData->addPoints(array(2,7,5,1,9,2),"Proba 3");
$MyData->setSerieTicks("Proba 2",4);
$MyData->setSerieWeight("Proba 3",2);
$MyData->setAxisName(0,"Note");
$MyData->addPoints(array("Ian","Feb","Mar","Apr","Mai","Iun"),"Labels");
$MyData->setSerieDescription("Labels","Luni");
$MyData->setAbscissa("Labels");
// creaza obiectul chart
$myPicture = new pImage(700,230,$MyData);
//deseneaza fundalul
$Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
$myPicture->drawFilledRectangle(0,0,700,230,$Settings);
// suprapune un 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));
// bordura
$myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));
// titlul pozei
$myPicture->setFontProperties(array("FontName"=>"fonts/Silkscreen.ttf","FontSize"=>6));
$myPicture->drawText(10,13,"EXEMPLU",array("R"=>255,"G"=>255,"B"=>255));
// titlul graficului
$myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>11));
$myPicture->drawText(250,55,"Media Notelor",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
//deseneaza marimea 1
$myPicture->setGraphArea(60,60,450,190);
$myPicture->drawFilledRectangle(60,60,450,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
$AxisBoundaries = array(0=>array("Min"=>0,"Max"=>10));
$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE,"Mode"=>SCALE_MODE_MANUAL, "ManualScale"=>$AxisBoundaries);
$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"=>6));
$myPicture->drawLineChart(array("DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO));
$myPicture->setShadow(FALSE);
//deseneaza marimea 2
$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));
$myPicture->setShadow(TRUE,array("X"=>-1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
$myPicture->drawLineChart();
$myPicture->setShadow(FALSE);
// deseneaza legenda
$myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
//rendereaza poza
$myPicture->autoOutput("img/example.drawLineChart.png");
不幸的是,这会使整个页面如下所示:(我正在上传图片,因为您需要一个帐户才能看到它)
我做错了什么吗?我在一个函数中使用了这段代码。
此外,在 WAMP 示例中不起作用。有什么办法吗?