move window bars on simple x-y chart?

TeeChart for ActiveX, COM and ASP
Post Reply
Russ
Newbie
Newbie
Posts: 18
Joined: Thu Nov 02, 2006 12:00 am
Location: Chattanooga, TN
Contact:

move window bars on simple x-y chart?

Post by Russ » Wed Nov 29, 2006 2:35 pm

Hi: Now that I can succesfully add window bars (using ColorBand) to an x-y chart I would like to know how I can move those bars with mouse.

I would like for the user to be able to click on the band - then drag it left or right. Is that doable?

Best Regards,
russ

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Nov 29, 2006 3:28 pm

Hi Russ,

Yes, you can do that setting ResizeStart and ResizeEnd to true:

Code: Select all

    With TChart1.Tools.Items(0).asColorband
        .Axis = TChart1.Axis.Bottom
        .StartValue = 10
        .EndValue = 20
        .ResizeEnd = True
        .ResizeStart = True
    End With
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Russ
Newbie
Newbie
Posts: 18
Joined: Thu Nov 02, 2006 12:00 am
Location: Chattanooga, TN
Contact:

move window bars on simple x-y chart?

Post by Russ » Thu Nov 30, 2006 12:00 am

Narcis: Thank you, that works fine one edge at a time. What I would like to do is click somewhere on the ColorBand itself and drag the entire ColorBand as a whole - so that its width stays the same but the whole ColorBand moves.

Is that possible?

Regards,
russ

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Nov 30, 2006 9:03 am

Hi Russ,

Ok, then you can do something like this:

Code: Select all

Dim X0 As Integer
Dim BandStart, BandEnd As Double

Private Sub Form_Load()
    TChart1.Series(0).FillSampleValues 25
    X0 = -1
    BandStart = TChart1.Tools.Items(0).asColorband.StartValue
    BandEnd = TChart1.Tools.Items(0).asColorband.EndValue
End Sub

Private Sub TChart1_OnColorBandToolClick(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
    X0 = X
End Sub

Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
    Dim Offset As Double

    If (X0 <> -1) Then
        Offset = TChart1.Axis.Bottom.CalcPosPoint(X) - TChart1.Axis.Bottom.CalcPosPoint(X0)
    
        TChart1.Tools.Items(0).asColorband.StartValue = BandStart + Offset
        TChart1.Tools.Items(0).asColorband.EndValue = BandEnd + Offset
    End If
End Sub

Private Sub TChart1_OnMouseUp(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
    X0 = -1
    BandStart = TChart1.Tools.Items(0).asColorband.StartValue
    BandEnd = TChart1.Tools.Items(0).asColorband.EndValue
End Sub
Notice that in the example the ColorBand tool is associated to the bottom axis.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Russ
Newbie
Newbie
Posts: 18
Joined: Thu Nov 02, 2006 12:00 am
Location: Chattanooga, TN
Contact:

move window bars on simple x-y chart?

Post by Russ » Thu Nov 30, 2006 1:54 pm

Narcis: Thank you, this works great. The only caveat is that when moving the colorband with the mouse - i still get the stretch rectangle that is used to zoom in on the plot. So, after I move my colorband to the right the zoom occurs.

How can I defeat the zoom feature?

Best Regards,
russ

Russ
Newbie
Newbie
Posts: 18
Joined: Thu Nov 02, 2006 12:00 am
Location: Chattanooga, TN
Contact:

move window bars on simple x-y chart?

Post by Russ » Thu Nov 30, 2006 3:09 pm

Narcis: I thought I found a solution with this command:

TChart1.Zoom.Enable = False 'disable zoom when colorband is present

It seems to be behaving funny. I added that line of code to my code that turns my ColorBand on. Likewise, when I turn off my ColorBand I set TChart1.Zoom.Enable = True.

This works great and I can turn the band on & off, move it with no problem and the zoom doesn't occur (works like I think it should).

The wierd behavoir occurs if I ever do a zoom. If I do a zoom while I have the ColorBand turned off, something is affected such that when I turn my ColorBand back on I can't see it. Its transparent.

Any idea what that could be?

Regards,
russ

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Nov 30, 2006 3:49 pm

Hi Russ,

Could you please send us a simple example we can run "as-is" to reproduce the problem here?

You can post your files at news://www.steema.net/steema.public.attachments newsgroup.

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Russ
Newbie
Newbie
Posts: 18
Joined: Thu Nov 02, 2006 12:00 am
Location: Chattanooga, TN
Contact:

move window bars on simple x-y chart?

Post by Russ » Fri Dec 01, 2006 2:07 am

Narcis: I apologize, I couldn't properly upload my sample code to the newsgroup. However, I have put a copy of it at the following URL:

http://webpages.charter.net/rwpatterson ... p/samp.zip

Narcis:

Steps to reproduce problem with sample code (samp.zip):
1) Open VB code and run.
2) Select "Show band" check box.
3) Move band around to see that it works (with mouse).
4) Deselect "Show band" check box.
5) Zoom in on the plot and then unzoom
6) Now select "Show band" again - the band is not visible (this is the problem).

The problem lies in the 2 lines of code that contain "TChart1.Zoom.Enable". Some weird incompatibility with toggleing zoom and using the ColorBand.

Best Regards,
russ[/img]

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Dec 01, 2006 9:37 am

Hi Russ,

Thanks for the example.

I guess the problem was with ColorBandMin and ColorBandMax that where weren't updated after zooming and the ColorBand stood at 0 position. This probably happens becasue Zoom event prevails over OnClick event. Changing the checkbox event like this works fine:

Code: Select all

Private Sub chkBand_Click()
    With TChart1.Tools.Items(0)
        .asColorband.Axis = Bottom
        .Active = chkBand.Value
        TChart1.Zoom.Enable = Not .Active
    End With
End Sub
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply