Page 1 of 1

move window bars on simple x-y chart?

Posted: Wed Nov 29, 2006 2:35 pm
by 9532946
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

Posted: Wed Nov 29, 2006 3:28 pm
by narcis
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

move window bars on simple x-y chart?

Posted: Thu Nov 30, 2006 12:00 am
by 9532946
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

Posted: Thu Nov 30, 2006 9:03 am
by narcis
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.

move window bars on simple x-y chart?

Posted: Thu Nov 30, 2006 1:54 pm
by 9532946
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

move window bars on simple x-y chart?

Posted: Thu Nov 30, 2006 3:09 pm
by 9532946
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

Posted: Thu Nov 30, 2006 3:49 pm
by narcis
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.

move window bars on simple x-y chart?

Posted: Fri Dec 01, 2006 2:07 am
by 9532946
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]

Posted: Fri Dec 01, 2006 9:37 am
by narcis
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