1

I am trying to name my x-axis (see picture).

Image without name on x-axis when my code sould print one.

As you can see, no x-axis name is printed. However, my code should print one because of this line: $MyData->setSerieDescription("Labels","Range of Data");, unless I misunderstand the usage.

Code:

 /* 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($LT50,$GT50_LT100,$GT100_LT150,$GT150_LT200,$GT200_LT250,$GT250_LT300,$GT300_LT350,$GT350_LT400,$GT400_LT450,$GT450),"Probe 3");
 $MyData->setSerieWeight("Probe 3",2);
 $MyData->setAxisName(0,"Number of Occurrences");;
 $MyData->addPoints(array("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"),"Labels");
 $MyData->setSerieDescription("Labels","Range of Data");
 $MyData->setAbscissa("Labels");


 /* 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 Diff Between TRWire Job Created and Crew Dispatched",array("FontSize"=>15,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));

 /* Set the default font */
 $myPicture->setFontProperties(array("FontName"=>"../fonts/pf_arma_five.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();

 /* Render the picture (choose the best way) */
 $myPicture->autoOutput("./pChart/examples/pictures/example.drawLineChart.simple.png");
Ryan_W4588
  • 648
  • 3
  • 13
  • 32

4 Answers4

5

This problem bugged the crap out of me. I was up late at night diagnosing just getting my graph to show up.

Related to the missing X-Axis title, I finally found grepping through the source directory that using $myData->setAbscissaName("Time of Reading"); worked for me. It was magical.

They have poor documentation. I even copied and pasted their example scripts that had a titled x-axis (which never worked as copied and pasted) and they turned out to not have a title either. VERY FRUSTRATING.

0

Ryan,

I took a look at the documentation for this library on Source Forge. It seems to suggest you should use method SetXAxisName to label the X axis and SetYAxisName to label the Y axis. Not sure why SetAxisName is correctly labeling the Y axis (maybe a deprecated version?) but I would change it.

SetSerieName is used to label a data series so that it shows up on a legend when you invoke drawLegend.

Hope this helps.

steve klein
  • 2,566
  • 1
  • 14
  • 27
  • I would agree that the documentation shows this. Howevever, after adding this it still does not show the label for the axis. I am starting to think that files either corrupted or didn't download correctly. – Ryan_W4588 Aug 04 '14 at 11:50
0

For anyone in the future:

I could not find out why my pChart was doing this. After reinstalling, nothing changed. So, to create a make-shift axis name, I generated a legend and placed it in the bottom middle of my chart. It works as a pretty effective axis name, although it would have been nice to get it working completely.

Final Code:

 /* 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");
Ryan_W4588
  • 648
  • 3
  • 13
  • 32
0

You can also make the outer box bigger and use drawText(), which gives you a little more control, and is easier to implement.

$myPicture->drawText(450, 55, "Width in Pixels", array("FontSize" => 15, "Align" => TEXT_ALIGN_BOTTOMMIDDLE));
Bob Ray
  • 1,105
  • 10
  • 20