Php 如何在pChart中标记x轴

Php 如何在pChart中标记x轴,php,pchart,Php,Pchart,我正在尝试命名我的x轴(见图) 如您所见,没有打印x轴名称。但是,我的代码应该打印一个,因为这行:$MyData->setSerieDescription(“标签”,“数据范围”),除非我误解了用法 代码: /*pChart库包含*/ 包括(“../class/pData.class.php”); 包括(“../class/pDraw.class.php”); 包括(“../class/pImage.class.php”); /*创建并填充pData对象*/ $MyData=new pData

我正在尝试命名我的x轴(见图)

如您所见,没有打印x轴名称。但是,我的代码应该打印一个,因为这行:
$MyData->setSerieDescription(“标签”,“数据范围”),除非我误解了用法

代码:

/*pChart库包含*/
包括(“../class/pData.class.php”);
包括(“../class/pDraw.class.php”);
包括(“../class/pImage.class.php”);
/*创建并填充pData对象*/
$MyData=new pData();
$MyData->添加点(阵列($LT50、$GT50_LT100、$GT100_LT150、$GT150_LT200、$GT200_LT250、$GT250_LT300、$GT300_LT350、$GT350_LT400、$GT400_LT450、$GT450),“探头3”);
$MyData->setSerieWeight(“探头3”,2);
$MyData->setAxisName(0,“出现次数”);;
$MyData->addPoints(数组(“Diff<50”、“50>Diff<100”、“100>Diff<150”、“150>Diff<200”、“200>Diff<250”、“250>Diff<300”、“300>Diff<350”、“350>Diff<400”、“400>Diff<450”、“Diff>450”)、“标签”);
$MyData->setSerieDescription(“标签”、“数据范围”);
$MyData->setAbscissa(“标签”);
/*创建pChart对象*/
$myPicture=new pImage(1500690$MyData);
/*抗锯齿回合*/
$myPicture->Antialias=FALSE;
/*为图片添加边框*/
$myPicture->drawRectangle(0,01440675,数组(“R”=>0,“G”=>0,“B”=>0));
/*写下图表标题*/
$myPicture->setFontProperties(数组(“FontName”=>”./fonts/Forgotte.ttf,“FontSize”=>20));
$myPicture->drawText(250,35,“创建的TRWire作业和分派的工作人员之间的时间差”,数组(“FontSize”=>15,“Align”=>TEXT\u Align\u BOTTOMMIDDLE));
/*设置默认字体*/
$myPicture->setFontProperties(数组(“FontName”=>”./fonts/pf_arma_five.ttf,“FontSize”=>10));
/*定义图表区域*/
$myPicture->setGraphArea(60,401400600);
/*画天平*/
$AxisBounders=array(0=>array(“最小”=>0,“最大”=>$Max));
$scaleSettings=array(“模式”=>SCALE\U模式\U手动,“LabelRotation”=>30,“手动缩放”=>AxisBounders,“XMargin”=>10,“YMargin”=>10,“浮动”=>TRUE,“网格”=>200,“网格”=>200,“DrawSubTicks”=>TRUE,“循环背景”=>TRUE);
$myPicture->drawScale($scaleSettings);
/*启用抗锯齿*/
$myPicture->antialas=TRUE;
/*画线图*/
$myPicture->drawLineChart();
/*渲染图片(选择最佳方式)*/
$myPicture->autoOutput(“./pChart/examples/pictures/example.drawLineChart.simple.png”);
Ryan

我在SourceForge上查看了这个库的文档。似乎建议您使用方法SetXAxisName来标记X轴,使用方法SetYAxisName来标记Y轴。不确定为什么SetAxisName正确标记了Y轴(可能是不推荐的版本?),但我会更改它

SetSerieName用于标记数据系列,以便在调用drawLegend时它显示在图例上

希望这有帮助。

Ryan

我在SourceForge上查看了这个库的文档。似乎建议您使用方法SetXAxisName来标记X轴,使用方法SetYAxisName来标记Y轴。不确定为什么SetAxisName正确标记了Y轴(可能是不推荐的版本?),但我会更改它

SetSerieName用于标记数据系列,以便在调用drawLegend时它显示在图例上


希望这能有所帮助。

对于未来的任何人:

我不知道为什么我的pChart会这样做。重新安装后,没有任何更改。因此,为了创建一个临时轴名称,我生成了一个图例,并将其放置在图表的中间底部。它是一个非常有效的axis名称,不过如果能让它完全正常工作就好了

最终代码:

 /* 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($LT30,$GT60,$GT90,$GT120,$GT150,$GT180,$GT210,$GT240,$GT270,$GT300,$GT330,$GT360,$GT390,$GT420,$GT450,$GT480,$GT510,$GT540,$GT570,$GT600),"Time Range (minutes)");
 $MyData->setSerieWeight("Time Range (minutes)",2);
 $MyData->setAxisName(0,"Number of Occurrences");
 $MyData->addPoints(array("< 30","30-60","60-90","90-120","120-150","150-180","180-210","210-240","240-270","270-300","300-330","330-360","360-390","390-420","420-450","450-480","510-540","540-570","570-600","> 600"),"Labels");
 $MyData->setSerieDescription("Labels","Months");
 $MyData->setAbscissa("Labels");
 $MyData->SetXAxisName(1,"Range of Data");


 /* Create the pChart object */
 $myPicture = new pImage(1500,690,$MyData);

 /* Turn of Antialiasing */
 $myPicture->Antialias = FALSE;

 /* Add a border to the picture */
 $myPicture->drawRectangle(0,0,1440,675,array("R"=>0,"G"=>0,"B"=>0));

 /* Write the chart title */ 
 $myPicture->setFontProperties(array("FontName"=>"../fonts/Forgotte.ttf","FontSize"=>20));
 $myPicture->drawText(250,35,"Time Difference Between TRWire Job Created and Crew Dispatched in 2014",array("FontSize"=>15,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));

 /* Set the default font */
 $myPicture->setFontProperties(array("FontName"=>"../fonts/verdana.ttf","FontSize"=>10,));

 /* Define the chart area */
 $myPicture->setGraphArea(60,40,1400,600);

 /* Draw the scale */
$AxisBoundaries = array(0=>array("Min"=>0,"Max"=>$max));
 $scaleSettings = array("Mode"=>SCALE_MODE_MANUAL, "LabelRotation"=>30, "ManualScale"=>$AxisBoundaries, "XMargin"=>10,"YMargin"=>10,"Floating"=>TRUE,"GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE );
 $myPicture->drawScale($scaleSettings);

 /* Turn on Antialiasing */
 $myPicture->Antialias = TRUE;

 /* Draw the line chart */
 $myPicture->drawLineChart();
 $myPicture->drawPlotChart(array("DisplayValues"=>TRUE,"PlotBorder"=>TRUE,"BorderSize"=>2,"Surrounding"=>-60,"BorderAlpha"=>80));

 $myPicture->drawLegend(600,650,array("Style"=>LEGEND_BORDER,"Mode"=>LEGEND_HORIZONTAL));

 /* Render the picture (choose the best way) */
 $myPicture->autoOutput("./pChart/examples/pictures/example.drawLineChart.simple.png");
/*pChart库包含*/
包括(“../class/pData.class.php”);
包括(“../class/pDraw.class.php”);
包括(“../class/pImage.class.php”);
/*创建并填充pData对象*/
$MyData=new pData();
$MyData->addPoints(数组($LT30、$GT60、$GT90、$GT120、$GT150、$GT180、$GT210、$GT240、$GT270、$GT300、$GT330、$GT360、$GT390、$GT420、$GT450、$GT480、$GT510、$GT540、$GT570、$GT600),“时间范围(分钟)”;
$MyData->setSerieWeight(“时间范围(分钟)”,2);
$MyData->setAxisName(0,“出现次数”);
$MyData->addPoints(数组(“<30”、“30-60”、“60-90”、“90-120”、“120-150”、“150-180”、“180-210”、“210-240”、“240-270”、“270-300”、“300-330”、“330-360”、“360-390”、“390-420”、“420-450”、“450-480”、“510-540”、“540-570”、“570-600”、“600”)、“>600”)、“标签”);
$MyData->setSerieDescription(“标签”、“月份”);
$MyData->setAbscissa(“标签”);
$MyData->SetXAxisName(1,“数据范围”);
/*创建pChart对象*/
$myPicture=new pImage(1500690$MyData);
/*抗锯齿回合*/
$myPicture->Antialias=FALSE;
/*为图片添加边框*/
$myPicture->drawRectangle(0,01440675,数组(“R”=>0,“G”=>0,“B”=>0));
/*写下图表标题*/
$myPicture->setFontProperties(数组(“FontName”=>”./fonts/Forgotte.ttf,“FontSize”=>20));
$myPicture->drawText(250,35,“2014年创建的TRWire作业与派遣的工作人员之间的时间差”,数组(“FontSize”=>15,“Align”=>TEXT_Align_BOTTOMMIDDLE));
/*设置默认字体*/
$myPicture->setFontProperties(数组(“FontName”=>”./fonts/verdana.ttf,“FontSize”=>10,);
/*定义图表区域*/
$myPicture->setGraphArea(60,401400600);
/*画天平*/
$AxisBounders=array(0=>array(“最小”=>0,“最大”=>$Max));
$scaleSettings=array(“模式”=>SCALE\U模式\U手动,“LabelRotation”=>30,“手动缩放”=>AxisBounders,“XMargin”=>10,“YMargin”=>10,“浮动”=>TRUE,“网格”=>200,“网格”=>200,“DrawSubTicks”=>TRUE,“循环背景”=>TRUE);
$myPicture->drawScale($scaleSettings);
/*启用抗锯齿*/
$myPicture->antialas=TRUE;
/*画线图*/
$myPicture->drawLineChart();
$myPicture->drawPlotChart(数组(“DisplayValues”=>TRUE,“PlotBorder”=>TRUE,“BorderSize”=>2,“包围”=>60,“BorderAlpha”=>80));
$myPicture->drawLegend(600650,数组(“样式”=>LEGEND_边框,“模式”=>LEGEND_水平));
/*渲染图片(选择最佳方式)*/
$mypicture
 /* 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($LT30,$GT60,$GT90,$GT120,$GT150,$GT180,$GT210,$GT240,$GT270,$GT300,$GT330,$GT360,$GT390,$GT420,$GT450,$GT480,$GT510,$GT540,$GT570,$GT600),"Time Range (minutes)");
 $MyData->setSerieWeight("Time Range (minutes)",2);
 $MyData->setAxisName(0,"Number of Occurrences");
 $MyData->addPoints(array("< 30","30-60","60-90","90-120","120-150","150-180","180-210","210-240","240-270","270-300","300-330","330-360","360-390","390-420","420-450","450-480","510-540","540-570","570-600","> 600"),"Labels");
 $MyData->setSerieDescription("Labels","Months");
 $MyData->setAbscissa("Labels");
 $MyData->SetXAxisName(1,"Range of Data");


 /* Create the pChart object */
 $myPicture = new pImage(1500,690,$MyData);

 /* Turn of Antialiasing */
 $myPicture->Antialias = FALSE;

 /* Add a border to the picture */
 $myPicture->drawRectangle(0,0,1440,675,array("R"=>0,"G"=>0,"B"=>0));

 /* Write the chart title */ 
 $myPicture->setFontProperties(array("FontName"=>"../fonts/Forgotte.ttf","FontSize"=>20));
 $myPicture->drawText(250,35,"Time Difference Between TRWire Job Created and Crew Dispatched in 2014",array("FontSize"=>15,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));

 /* Set the default font */
 $myPicture->setFontProperties(array("FontName"=>"../fonts/verdana.ttf","FontSize"=>10,));

 /* Define the chart area */
 $myPicture->setGraphArea(60,40,1400,600);

 /* Draw the scale */
$AxisBoundaries = array(0=>array("Min"=>0,"Max"=>$max));
 $scaleSettings = array("Mode"=>SCALE_MODE_MANUAL, "LabelRotation"=>30, "ManualScale"=>$AxisBoundaries, "XMargin"=>10,"YMargin"=>10,"Floating"=>TRUE,"GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE );
 $myPicture->drawScale($scaleSettings);

 /* Turn on Antialiasing */
 $myPicture->Antialias = TRUE;

 /* Draw the line chart */
 $myPicture->drawLineChart();
 $myPicture->drawPlotChart(array("DisplayValues"=>TRUE,"PlotBorder"=>TRUE,"BorderSize"=>2,"Surrounding"=>-60,"BorderAlpha"=>80));

 $myPicture->drawLegend(600,650,array("Style"=>LEGEND_BORDER,"Mode"=>LEGEND_HORIZONTAL));

 /* Render the picture (choose the best way) */
 $myPicture->autoOutput("./pChart/examples/pictures/example.drawLineChart.simple.png");
$myPicture->drawText(450, 55, "Width in Pixels", array("FontSize" => 15, "Align" => TEXT_ALIGN_BOTTOMMIDDLE));