Hey people,
I'm having a rather frustrating error - "The scale seems to be too small to hold any of the specified tick marks".
My code is here:
<?php
//
// Basic example on how to use custom tickmark feature to have a label
// at the start of each month.
//
include ("../jpgraph.php");
include ("../jpgraph_line.php");
include ("../jpgraph_utils.inc.php");
$litresToGallons = 0.22;
$dbserver = "mysql";
$db = "databasename";
$username = "username";
$password = "password";
if ( mysql_connect($dbserver, $username, $password) ) {
if ( mysql_select_db("$db") ) {
$result = mysql_query("SELECT vehicle.name,mileage.pence_per_litre,mileage.cost_of_fuel_added,mileage.miles_since_last_fillup,mileage.date_of_fillup FROM mileage,vehicle WHERE mileage.vehicle = vehicle.id AND mileage.vehicle = 1 ORDER BY mileage.date_of_fillup ASC");
$numberOfRows = mysql_numrows($result);
for ($i=0; $i<$numberOfRows; $i++) {
$pencePerLitre = mysql_result($result, $i, "mileage.pence_per_litre");
$costOfFuelAdded = mysql_result($result, $i, "mileage.cost_of_fuel_added");
$milesSinceLastFillup = mysql_result($result, $i, "mileage.miles_since_last_fillup");
$dateOfPreviousFillup = mysql_result($result, $i-1, "mileage.date_of_fillup");
$dateOfFillup = mysql_result($result, $i, "mileage.date_of_fillup");
$litresPutIntoTank = round($costOfFuelAdded / ( $pencePerLitre / 100 ),2);
$milesPerLitre = round($milesSinceLastFillup / $litresPutIntoTank,2);
$milesPerGallon = round($milesPerLitre / $litresToGallons,2);
$pencePerMile = round(($costOfFuelAdded / $milesSinceLastFillup) * 100,2);
$datax[] = strtotime($dateOfFillup);
$datay[] = $milesPerGallon;
}
}
}
//
// Create some random data for the plot. We use the current time for the
// first X-position
//
//$ts = time()-1200000;
//for($i=0; $i < $numberOfRows; ++$i ) {
// $datax[$i] = $ts+$i*700000;
//}
// Now get labels at the start of each month
$dateUtils = new DateScaleUtils();
list($tickPositions,$minTickPositions) = $dateUtils->GetTicks($datax);
// We add some grace to the end of the X-axis scale so that the first and last
// data point isn't exactly at the very end or beginning of the scale
$grace = 400000;
$xmin = $datax[0]-$grace;
$xmax = $datax[$numberOfRows-1]+$grace;
//
// The code to setup a very basic graph
//
$graph = new Graph(1024,400);
//
// We use an integer scale on the X-axis since the positions on the X axis
// are assumed to be UNI timestamps
$graph->SetScale('intlin',0,0,$xmin,$xmax);
$graph->title->Set(strtotime($dateOfFillup));
//$graph->title->SetFont(FF_ARIAL,FS_NORMAL,12);
//
// Make sure that the X-axis is always at the bottom of the scale
// (By default the X-axis is alwys positioned at Y=0 so if the scale
// doesn't happen to include 0 the axis will not be shown)
$graph->xaxis->SetPos('min');
// Now set the tic positions
$graph->xaxis->SetTickPositions($tickPositions,$minTickPositions);
// The labels should be formatted at dates with "Year-month"
//$graph->xaxis->SetLabelFormatString('My',true);
// Use Ariel font
//$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,9);
// Add a X-grid
$graph->xgrid->Show();
// Create the plot line
$p1 = new LinePlot($datay,$datax);
$p1->SetColor('teal');
$graph->Add($p1);
// Output graph
$graph->Stroke();
?>
Can anyone tell me what has gone wrong??
Thank you in advance to anyone who can help!