ASE Home Page Products Download Purchase Support About ASE
ChartDirector General
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  x axis data bar starting before setDateScale tick
Posted by joeg on Mar-29-2012 05:45
Attachments:
Hi Peter,
I have the following situation:

The first data bar on the x axis is starting on the left of the first tick. The date/time range is set up by SetDateScale(beg, end).
here is my code:


  # The data for the bar chart
  $data = [31, 52, 53, 44, 35, 46, 77, 78, 89];

    my $dates = [
      perlchartdir::chartTime( 2012, 3, 20, 10,  1, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10,  6, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 11, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 16, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 21, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 26, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 31, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 36, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 41, 0),
      ];
                                                                                     13,45         Top


#Create XYChart object
  $c = new XYChart(590, 350, 0xf4f4f4, 0xffffff );

  # Set the plotarea
  $c->setPlotArea( 70, 5, 510, 270, 0xffffff, -1, -1, 0xcccccc, 0xcccccc );

  # Add a bar chart layer using the given data
  $layer = $c->addBarLayer($data);
  $layer->setXData($dates);
  $layer->setBarGap($perlchartdir::TouchBar);
  $c->xAxis()->setMargin(63,63);

  # Set the labels on the x axis.

  $c->xAxis()->setDateScale(
              perlchartdir::chartTime(2012, 3, 20, 10, 0, ),
              perlchartdir::chartTime(2012, 3, 20, 10, 45),
          );


The first bar should not start before 10:00 - what am i missing .
thank you
mychart.pl.png

  Re: x axis data bar starting before setDateScale tick
Posted by Peter Kwan on Mar-30-2012 00:11
Hi Joeg,

In your code, the first bar is at 10:01:00. However, the bar also has a width. In your code, it is not clear what the bar width should be (especially what the bar width of the first bar should be), but as the bar touches, it should be around 5 minutes. It means the first bar is centered at 10:01:00 and has a width of 5 minutes. So the first bar should be from 9:58:30 to 10:03:30. That is why the first bar should start slightly before 10:00:00.

If your intention is to have the first bar in between 10:00:00 and 10:05:00, instead of using 10:01:00, 10:06:00, ... as the bar positions, you may use 10:02:30, 10:07:30, .... instead.

As alternative method is to use a label based x-axis, like:

my $data = [$perlchartdir::NoValue, 31, 52, 53, 44, 35, 46,
     77, 78, 89, $perlchartdir::NoValue];

my $dates = [
      perlchartdir::chartTime( 2012, 3, 20, 10,  0, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10,  5, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 10, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 15, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 20, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 25, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 30, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 35, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 40, 0),
      perlchartdir::chartTime( 2012, 3, 20, 10, 45, 0),
      ];


#Create XYChart object
$c = new XYChart(590, 350, 0xf4f4f4, 0xffffff );

# Set the plotarea
$c->setPlotArea( 70, 5, 510, 270, 0xffffff, -1, -1, 0xcccccc, 0xcccccc );

# Add a bar chart layer using the given data
$layer = $c->addBarLayer($data);
$layer->setBarGap($perlchartdir::TouchBar);

# Set the labels on the x axis.
$c->xAxis()->setLabels2($dates, "{value|hh:nn:ss}");
$c->xAxis()->setLabelStep(2);
$c->xAxis()->setLabelOffset(0.5);
$c->xAxis()->setTickOffset(0.5);

Hope this can help.

Regards
Peter Kwan

  Re: x axis data bar starting before setDateScale tick
Posted by joeg on Mar-30-2012 23:37
Thank You Peter
I'll go with your first explanation
" In your code, the first bar is at 10:01:00. However, the bar also has a width. In your code, it is not clear what the bar width should be (especially what the bar width of the first bar should be), but as the bar touches, it should be around 5 minutes. It means the first bar is centered at 10:01:00 and has a width of 5 minutes. So the first bar should be from 9:58:30 to 10:03:30. That is why the first bar should start slightly before 10:00:00."
as I can not change the data. It comes from a sql giving a user's request for a rage of date and time. In my example I copied the little script I used to test.

Thank so much for your time.   JoeG

  Re: x axis data bar starting before setDateScale tick
Posted by Peter Kwan on Mar-30-2012 00:13
Hi joeg,

I have just response to your same enquiry in the ChartDiector General forum. See:

http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_general&thread=1332971147#N1333037511

Hope this can help.

Regards
Peter Kwan