我写了一个绘制 jpGraph 线图的代码。X 轴包含时间值,即小时 01:00、02:00 等。Y 轴包含频率数。问题是 X 轴从 01:00 开始,尽管我希望它从 00:00 开始。有谁知道为什么会发生这种情况以及如何避免这种转变?
<?php
ob_start();
include_once ( "../jpgraph-3.5.0b1/src/jpgraph.php");
include_once ("../jpgraph-3.5.0b1/src/jpgraph_bar.php");
include_once ("../jpgraph-3.5.0b1/src/jpgraph_line.php");
include_once ("../jpgraph-3.5.0b1/src/jpgraph_date.php");
include_once "../jpgraph-3.5.0b1/src/jpgraph_canvas.php";
//...data array
$totalSec = 0; $stepSec = 60;
$ntimepoints = 1440;
$datax = array();
$datay = array();
for( $i=0; $i < $ntimepoints; $i++ ) {
$datax[$i] = $totalSec;
$datay[$i] = numberOfFits($data,$totalSec);
$totalSec = $totalSec + $stepSec;
}
// Create the new graph
$graph = new Graph(1200,300,"auto");
// Slightly larger than normal margins at the bottom to have room for
// the x-axis labels
$graph->SetMargin(60,30,30,40);
// Fix the Y-scale and use date for the x-axis
$graph->SetScale('datlin');
// Set the angle for the labels to 90 degrees
$graph->xaxis->SetLabelAngle(90);
$graph->xaxis->SetColor("black","#274E7D");
$graph->yaxis->SetColor("black","#274E7D");
$graph->yaxis->SetTitleMargin(40);
// Set up font for axis
//$graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,8);
$graph->yaxis->SetFont(FF_VERDANA,FS_NORMAL,10);
$graph->yaxis->title->Set("Nr of resources");
$graph->yaxis->title->SetColor("#274E7D");
$graph->yaxis->title->SetFont(FF_VERDANA,FS_NORMAL,10);
// Set up X-axis title (color & font)
//$graph->xaxis->title->Set("Time");
$graph->xaxis->title->SetColor("#274E7D");
$graph->xaxis->title->SetFont(FF_VERDANA,FS_NORMAL,10);
$graph->xaxis->scale->SetTimeAlign(MINADJ_60);
$graph->xaxis->scale->SetDateFormat('H:i');
$line = new LinePlot($datay,$datax);
$line->SetFillColor('#6899D3@0.5');
//$line->SetStepStyle();
$graph->Add($line);
$graph->Stroke();
}