1

jpGraph の折れ線グラフを描画するコードを書きました。X 軸には時間の値 (01:00、02:00 など) が含まれます。Y 軸には周波数番号が含まれます。問題は、X 軸が 00:00 から始まると思っていたのに、01: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 &amp; 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();
    } 
4

0 に答える 0