I'm trying to create a graph with a maximum of three datasets from mysql. Everything works perfectly other than its not rendering the axis names for anything but the first set....
My chart code is below (i've left out all the mysql calls for simplicity). $tt array contains the names of each series of data.
Code:
$tt[1] = $_GET[trendtype1];
$tt[2] = $_GET[trendtype2];
$tt[3] = $_GET[trendtype3];
//* Create and populate the pData object */
$MyData = new pData();
$noOfCharts = 0;
for ($x=1; $x <= 3; $x++) {
if ($tt[$x] != '') {
$y = $x - 1;
//var_dump($ttvalues[$x])."<br>";
$MyData->addPoints($ttvalues[$x],$tt[$x]);
$MyData->setAxisName($y,$tt[$x]);
$MyData->setSerieOnAxis($tt[$x],$y);
$noOfCharts++;
}
}
$MyData->setAxisPosition(2,AXIS_POSITION_RIGHT);
/* Bind a data serie to the X axis */
$MyData->addPoints($dataDatesArr,"Dates");
$MyData->setSerieDescription("Dates","Dates");
$MyData->setAbscissa("Dates");
$MyData->setAbscissaName("Dates");
/* Create the pChart object */
$myPicture = new pImage(700,530,$MyData);
/* Turn of Antialiasing */
$myPicture->Antialias = FALSE;
/* Add a border to the picture */
$myPicture->drawRectangle(0,0,699,400,array("R"=>0,"G"=>0,"B"=>0));
/* Write the chart title */
$myPicture->setFontProperties(array("FontName"=>$INC_DIR."/fonts/Forgotte.ttf","FontSize"=>11));
$myPicture->drawText(30,35,"Trend Report",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMLEFT));
/* Set the default font */
$myPicture->setFontProperties(array("FontName"=>$INC_DIR."/fonts/pf_arma_five.ttf","FontSize"=>6));
/* Define the chart area */
$myPicture->setGraphArea(90,90,600,300);
/* Draw the scale */
$ScaleSettings = array("DrawSubTicks"=>FALSE, "Mode"=>SCALE_MODE_ADDALL_START0, "Factors"=>array(1));
$myPicture->drawScale($ScaleSettings);
/* Turn on Antialiasing */
$myPicture->Antialias = TRUE;
/* Write the chart legend */
$myPicture->drawLegend(100,45,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
/* Draw the line chart */
$myPicture->setFontProperties(array("FontName"=>$INC_DIR."/fonts/pf_arma_five.ttf","FontSize"=>10));
for ($x=1; $x <= $noOfCharts; $x++) {
switch ($x) {
case 1:
$MyData->setSerieDrawable($tt[1],TRUE);
$MyData->setSerieDrawable($tt[2],FALSE);
$MyData->setSerieDrawable($tt[3],FALSE);
break;
case 2:
$MyData->setSerieDrawable($tt[2],TRUE);
$MyData->setSerieDrawable($tt[1],FALSE);
$MyData->setSerieDrawable($tt[3],FALSE);
break;
case 3:
$MyData->setSerieDrawable($tt[3],TRUE);
$MyData->setSerieDrawable($tt[2],FALSE);
$MyData->setSerieDrawable($tt[1],FALSE);
break;
default:
break;
}
if ($tt[$x] == "Grade") {
$myPicture->drawPlotChart(array("DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO));
} else {
$myPicture->drawLineChart(array("DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO));
}
}
/* Render the picture (choose the best way) */
$myPicture->autoOutput("chart.png");
?>