Wideshanks
New pChart user
Joined: Wed Jun 22, 2011 3:00 pm Posts: 1
|
Using the ForceLabels array in a scatter plot
It doesn't seem to be working: it still displays the regular values no matter what I override them with Relevant code: Code: $LabelPositions = array(0,1,2); $LabelCaptions = array('a','b','c'); $LabelSettings = array("Decimals"=>1,"ForceLabels"=>$LabelCaptions,"NoTitle"=>TRUE); $myScatter->writeScatterLabel(0,$LabelPositions,$LabelSettings);
Am I using it wrong? Does it not work in scatter plots? It is worth noting the only place I've seen a label actually overridden is on http://wiki.pchart.net/doc.draw.writeLabel.html which is a line chart. Rest of program: Code: <?php
$log = 0;
= mysql_pconnect($dbhost, $dbuser, $dbpass); if( !$dbh ) { print("Failed"); } mysql_select_db($dbbase,$dbh);
/* pChart library inclusions */ include("class/pData.class.php"); include("class/pDraw.class.php"); include("class/pImage.class.php"); include("class/pScatter.class.php");
/* Create the pData object */ $MyData = new pData();
// Data $today = date('Y-m-d 23:59:59');
$days = $_GET['days']; $departmentid = $_GET['dept']; $max = $_GET['max']; $label = $_GET['label'];
if ($departmentid == 0) { $department_clause = ''; } else { $department_clause = "and departmentid = $departmentid"; }
$end = strtotime($today); $start = strtotime("-$days days", $end );
$ticket_sql = " select ticketid, dateline from `swtickets` where laststaffreplytime > 0 ". $department_clause ." and dateline between $start and $end order by dateline desc ";
if ($log==1) { print "Max is ".$max."<br />"; print "<h1>Ticket SQL</h1><code>".$ticket_sql."</code><br />"; }
$pointer = mysql_query($ticket_sql);
while ($row = mysql_fetch_row($pointer)) { $ticketid = $row[0]; $ticketdate = $row[1]; if ($log==1) { print "<h3>Processing ticket $ticketid</h3>"; }
$first_sql = " select dateline, staffid from `swticketposts` where ticketid = $ticketid order by dateline asc limit 0,1 "; if ($log==1) { print "<h6>Client SQL</h6>".$first_sql."<br />"; } $first_pointer = mysql_query($first_sql); $first_row = mysql_fetch_row($first_pointer); $first_post = $first_row[0];
$is_staff = $first_row[1]; // if staffid != 0, then the first ticket was made by staff. // The real staff response needs to use limit 1,1 // if staffid == 0, then the first ticket is non-staff // The staff response needs to use limit 0,1 if ($is_staff != 0) { $limit_clause = "limit 1,1"; } else { $limit_clause = "limit 0,1"; } $staff_sql = " select dateline from `swticketposts` where ticketid = $ticketid and staffid != 0 order by dateline asc ".$limit_clause; if ($log==1) { print "<h6>Staff SQL</h6>".$staff_sql."<br />"; } $staff_pointer = mysql_query($staff_sql); $staff_row = mysql_fetch_row($staff_pointer); $staff_post = $staff_row[0];
$response = $staff_post - $first_post; $response = $response / 3600; if ($log==1) { print "<h6>Results</h6>"; print "Date: ".$ticketdate."<br />"; print "Response: ".$response."<br />"; }
$MyData -> addPoints($response,'responsetime'); $MyData -> addPoints($ticketdate,'dateline'); }
//$xmin = $MyData->getMin("dateline"); //$xmax = $MyData->getMax("dateline"); $xmin = $start; $xmax = $end; $ymax = 24; // initial value if (isset($max)) { $ymax = $max; } else { $ymax = $MyData->getMax("responsetime"); }
// X $MyData->setSerieOnAxis("dateline",0); $MyData->setAbscissa("dateline"); $MyData->setAxisPosition(0,AXIS_POSITION_BOTTOM); $MyData->setAxisXY(0,AXIS_X); $MyData->setAxisDisplay(0,AXIS_FORMAT_DATE,"M d");
// Y $MyData->setSerieOnAxis("responsetime",1); $MyData->setAxisName(1,"Hours"); $MyData->setAxisXY(1,AXIS_Y); $MyData->setAxisPosition(1,AXIS_POSITION_RIGHT); //$MyData->setAxisDisplay(1,AXIS_FORMAT_TIME,"H:i");
/* Create the 1st scatter chart binding */ $MyData->setScatterSerie("dateline","responsetime",0); $MyData->setScatterSerieDescription(0,"Ticket responses"); $MyData->setScatterSerieColor(0,array("R"=>0,"G"=>0,"B"=>0));
/* Create the pChart object */ $myPicture = new pImage(700,230,$MyData);
/* Add a border to the picture */ $myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));
/* Set the default font */ $myPicture->setFontProperties(array("FontName"=>"fonts/pf_arma_five.ttf","FontSize"=>6));
/* Define the chart area */ $myPicture->setGraphArea(10,10,665,190);
/* Create the Scatter chart object */ $myScatter = new pScatter($myPicture,$MyData);
$AxisBoundaries = array( 0=>array( "Min"=>$xmin, "Max"=>$xmax), 1=>array( "Min"=>0, "Max"=>$ymax ));
$ScaleSettings = array( "GridR"=>200, "GridG"=>200, "GridB"=>200, "CycleBackground"=>TRUE, "Mode"=>SCALE_MODE_MANUAL, "ManualScale"=>$AxisBoundaries );
$myScatter->drawScatterScale($ScaleSettings); //$myScatter->drawScatterScale();
/* Turn on shadow computing */ $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
/* Draw a scatter plot chart */ $myScatter->drawScatterPlotChart();
$LabelPositions = array(0,1,2); $LabelCaptions = array('a','b','c');
if ($label == 1) { $LabelSettings = array("Decimals"=>1,"ForceLabels"=>$LabelCaptions,"NoTitle"=>TRUE); $myScatter->writeScatterLabel(0,$LabelPositions,$LabelSettings); }
/* Render the picture (choose the best way) */ if ($log!=1) { $myPicture->autoOutput("pictures/example.drawScatterPlotChart.png"); } ?>
|