Axis scaling and overlapping data

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
norman
Newbie
Newbie
Posts: 82
Joined: Fri Jan 25, 2008 12:00 am

Axis scaling and overlapping data

Post by norman » Mon Jul 20, 2009 9:16 am

Hi,

I've noticed an issue with the display of data when axis min/max's are not set to automatic.

I have added two custom axis to my chart with start and end positions of 100,50 and 50,0 respectively. When the page loads for the first time the axes min and max's are set to automatic (i.e. the scales automatically adjust to the min and max series values - see image1 - the blue series min is 120).
image1.gif
image1
image1.gif (2.8 KiB) Viewed 8567 times
I have provided the end user with the ability to customize the axes min and max's, i.e. to allow them specify a min and/or max value to which to scale the axis. When the chart is redrawn I get data overlapping between the two series - see image2 - this is what happens when the blue axis min is set to 160. Note the blue series is now overlapping the red series.
image2.gif
image2
image2.gif (2.99 KiB) Viewed 8568 times
To change the scale I set the blue axis Automatic property to false and then set the axis Minimum property to the desired value e.g. 160, for example:

Code: Select all

axis.AutomaticMinimum = False
axis.Minimum = 160
Is this correct? The desired effect I was expecting was that the first 3 points in the blue series would no longer be visible (see image3 which I edited to illustrate the desired result).
image3.gif
image3
image3.gif (2.64 KiB) Viewed 8565 times
I’m using version 3.5.3371.26405 (i.e. framework 2.0 build 25th March).

Regards,

Norman

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Axis scaling and overlapping data

Post by Yeray » Mon Jul 20, 2009 11:48 am

Hi norman,

Have you seen the demo at All features\Welcome !\Axes\Opaque zones? You should find demos and tutorials at TeeChart programs group.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

norman
Newbie
Newbie
Posts: 82
Joined: Fri Jan 25, 2008 12:00 am

Re: Axis scaling and overlapping data

Post by norman » Mon Jul 20, 2009 12:07 pm

Hi Yeray,

To be honest I hadn't. I expected that the functionality described would have been the default behaviour. I'm not sure in how many cases you'd want overlapping data when you've gone to the trouble of creating individual custom axes and assigning a single series to each.

I'll take a closer look.

Thanks,

Norman

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Axis scaling and overlapping data

Post by Yeray » Mon Jul 20, 2009 2:34 pm

Hi Norman,

There are many customers who use custom axis, normally with a different distribution than yours, for whose enabling an "opaque zones" by default would broke their expected result.

Maybe it would be possible doing some previous distribution verifications, but every new verification has a little cost in performance.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

norman
Newbie
Newbie
Posts: 82
Joined: Fri Jan 25, 2008 12:00 am

Re: Axis scaling and overlapping data

Post by norman » Mon Jul 20, 2009 4:05 pm

Hi Yeray,

I have manged to prevent the data overlapping using the code in the aforementioned example, thanks, however I have a related problem.

I have annotations attached to some points and if the points are hidden the annotations are still displayed (see below - image1 is before the chart is rescaled, image2 is after the chart is rescaled - note the annotation 'A' is still visible). I'd like to hide such annotations. Can you suggest how best to achieve this? Currently I position the annotations in the charts AfterDraw event after getting the location of the point to which to attach it to, e.g.:

Code: Select all

tmpX = ch(seriesIndex).CalcXPos(pointIndex)
tmpY = ch(seriesIndex).CalcYPos(pointIndex)
With annotation
   .Left = tmpX - (.Width / 2)
   .Top = tmpY - (.Height + 15)
   With .Callout
      .XPosition = tmpX
      .YPosition = tmpY
      .ZPosition = 0
   End With
End With
How can I determine if the annotation and callouts are outside/inside the rectangle formed by the series axes and hide/show them accordingly?
image1.gif
image1
image1.gif (6.05 KiB) Viewed 8540 times
image2.gif
image2
image2.gif (5.99 KiB) Viewed 8541 times
Thanks,

Norman

norman
Newbie
Newbie
Posts: 82
Joined: Fri Jan 25, 2008 12:00 am

Re: Axis scaling and overlapping data

Post by norman » Mon Jul 20, 2009 4:32 pm

Hi,

Following my previous post I had a go at the following which seems to work:

Code: Select all

tmpX = ch(seriesIndex).CalcXPos(pointIndex)
tmpY = ch(seriesIndex).CalcYPos(pointIndex)

With annotation
   .Left = tmpX - (.Width / 2)
   .Top = tmpY - (.Height + 15)
   With .Callout
      .XPosition = tmpX
      .YPosition = tmpY
      .ZPosition = 0
   End With
End With

Dim left As Integer = ch.Series(seriesIndex).GetHorizAxis.IStartPos
Dim right As Integer = ch.Series(seriesIndex).GetHorizAxis.IEndPos
Dim top As Integer = ch.Series(seriesIndex).GetVertAxis.IStartPos
Dim bottom As Integer = ch.Series(seriesIndex).GetVertAxis.IEndPos

Dim rect As New Rectangle(left, top, right, bottom)
If Not rect.Contains(tmpX, tmpY) Then
   annotation.Active = False
End If
Can you confirm that this is the correct way to go?

Thanks,

Norman

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Axis scaling and overlapping data

Post by Yeray » Tue Jul 21, 2009 8:02 am

Hi Norman,

I can't see any difference between the two codes you posted. Anyway, adding this code in the AfterDraw event should hide your annotation when the point is out of its axis range:

Code: Select all

        If (TChart1(seriesIndex).YValues(pointIndex) < TChart1(seriesIndex).GetVertAxis.Minimum) Or (TChart1(seriesIndex).YValues(pointIndex) > TChart1(seriesIndex).GetVertAxis.Maximum) Then
            annotation.Active = False
        Else
            annotation.Active = True
        End If
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

norman
Newbie
Newbie
Posts: 82
Joined: Fri Jan 25, 2008 12:00 am

Re: Axis scaling and overlapping data

Post by norman » Tue Jul 21, 2009 8:30 am

Hi,

Thanks for the reply.

Original code was:

Code: Select all

tmpX = ch(seriesIndex).CalcXPos(pointIndex)
tmpY = ch(seriesIndex).CalcYPos(pointIndex)

With annotation
   .Left = tmpX - (.Width / 2)
   .Top = tmpY - (.Height + 15)
   With .Callout
      .XPosition = tmpX
      .YPosition = tmpY
      .ZPosition = 0
   End With
End With
Revised code contained these additional lines

Code: Select all

Dim left As Integer = ch.Series(seriesIndex).GetHorizAxis.IStartPos
Dim right As Integer = ch.Series(seriesIndex).GetHorizAxis.IEndPos
Dim top As Integer = ch.Series(seriesIndex).GetVertAxis.IStartPos
Dim bottom As Integer = ch.Series(seriesIndex).GetVertAxis.IEndPos

Dim rect As New Rectangle(left, top, right, bottom)
If Not rect.Contains(tmpX, tmpY) Then
   annotation.Active = False
End If
where tmpX and tmpY are the coords of the point to which the annotation is attached.

Regards,

Norman

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Axis scaling and overlapping data

Post by Yeray » Tue Jul 21, 2009 9:45 am

Hi Norman,

Yes, this code looks nice.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply