I posted this problem on the jpgraph forum, but I don't think that gets as much traffic and I thought I might find someone with some info on this issue here:

Hi;

I'm excited about the possibilities of the jpgraph_date.php date axis, but I can't seem to get it to restrict the X axis to single days: some default seems to be set that always gives me 2 points for each day along the X-axis (ie. midnight and noon). I'm dealing with data that should typically only have one observation per day. So, on the X-axis (date) I only want to see:

2005-09-06
2005-09-07
2005-09-08
2005-09-09
etc.

NOT
2005-09-06 00:00
2005-09-06 12:00
2005-09-07 00:00
2005-09-07 12:00

A sample of the data array (dates) I have is lilke so:
$xdata = array('1125982800', '1126069200', '1126155600', '1126242000', '1126328400', '1126414800', '1126501200');
and sample observation measures are
$data = array('-1','0','1','2','3','4');

I'm just getting started with this and so far I have just substituted my sample data into the dateaxisex2.php code in the /Examples folder. I have not messed with the rest of the code. Everything works fine except for the darned double dates. I can't seem to find anything in the manual or class reference that seems to bear on this issue specifically.

    please give more specifics on exactly which file in the Examples directory you are altering. I am having a lot of success displaying only one day. Post your altered file here and I will see what advice I can give you.

      Thank you for your reply. I made a little progress, (but I'm thinking it might be sort of a kludge rather than "the" solution. Here is example code:

      <?php
      require_once("jpgraph.php");
      require_once("jpgraph_line.php");
      require_once("jpgraph_date.php");
      
      $xdata = array('1125810000', '1125896400', '1125982800', '1126414800', '1126501200');
      $data = array('-2','-','0','2','4');
      
      // Create the new graph
      $graph = new Graph(900,600);
      
      // Slightly larger than normal margins at the bottom to have room for
      // the x-axis labels
      $graph->SetMargin(40,40,30,130);
      
      // Fix the Y-scale to go between [-4 and 4] and use date for the x-axis
      $graph->SetScale('datint',-4,4,0,0);
      $graph->title->Set("GAS DATA on Date scale TEST");
      
      // Set the angle for the labels to 90 degrees
      $graph->xaxis->SetLabelAngle(90);
      
      //$graph ->xaxis->scale-> SetDateAlign( DAYADJ_1);
      
      // It is possible to adjust the density for the X-axis as well
      // The following call makes the dates a little more sparse
      
      //***** THIS SEEMS TO WORK TO GET SINGLE DAYS ON THE X-AXIS ******
      $graph->SetTickDensity(TICKD_SPARSE,TICKD_VERYSPARSE);
      
      // The automatic format string for dates can be overridden
      //$graph->xaxis->scale->SetDateFormat('h:i');
      $graph->xaxis->scale->SetDateFormat('M-d');
      
      // Set X-axis at the minimum value of Y-axis (default will be at 0)
      $graph->xaxis->SetPos("min");    // "min" will position the x-axis at the minimum value of the Y-axis 
      
      // Adjust the start/end to a specific alignment
      //$graph->xaxis->scale->SetTimeAlign(MINADJ_15);
      
      $line = new LinePlot($data,$xdata);
      $line->SetLegend('Observations');
      $line->mark->SetType(MARK_FILLEDCIRCLE);
      $line->mark->SetFillColor("red");
      $line->mark->SetWidth(4); 
      //$line->SetFillColor('lightblue@0.5');
      
      $graph->Add($line);
      $graph->Stroke();
      ?>

      the original file in the /Examples folder is: dateaxisex2.php

        Ok I see what you are trying to do. If you need some fine tuning you can set the rate of generated X-ticks by hand.

        this will make more ticks than you can put on a dog.

        $graph->xtick_factor = 1;

        SetTickDensity() just uses some constants to choose which value xtick_factor is set to.. so why not just do it yourself.

          Poking around in the source I found

          jpgraph.php line 3694
          class Axis {
              ...
              var $label_step=1; 
              // Used by a text axis to specify what multiple of major steps should be labeled.
              ....
          }
          

          which seems to say 2 means, only label every other entry. That might actually solve your problem better.

            Write a Reply...