Resize chart with Selector Tool

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
asupriya
Advanced
Posts: 179
Joined: Mon Dec 01, 2008 12:00 am

Resize chart with Selector Tool

Post by asupriya » Thu Jun 11, 2009 5:26 am

Is there a way to resize chart by using mouse drag and selector tool?

If so, can you please post a vb.net example?

Thanks

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Resize chart with Selector Tool

Post by Sandra » Fri Jun 12, 2009 11:21 am

Hello asupriya,

I make a simple example, that i think solve your problem. Please Check that next code works fine.

InitializeChart:

Code: Select all

    Private FastLine1 As Steema.TeeChart.Styles.FastLine
    Private selector1 As Steema.TeeChart.Tools.Selector
    Private Sub InitializeChart()
        TChart1.Aspect.View3D = False
        FastLine1 = New Steema.TeeChart.Styles.FastLine(TChart1.Chart)
        selector1 = New Steema.TeeChart.Tools.Selector(TChart1.Chart)
        FastLine1.FillSampleValues()
        selector1.AllowResizeChart = True
    End Sub
I hope that will helps.

Thanks,
Best Regards,
Sandra Pazos / 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

asupriya
Advanced
Posts: 179
Joined: Mon Dec 01, 2008 12:00 am

Re: Resize chart with Selector Tool

Post by asupriya » Sat Jun 13, 2009 3:09 am

Thanks. It works.

How do I set the mouse cursor to double-diagonal arrow to indicate that border is resiable? Essentially, I like the mouse cursor to be reset to double headed arrow when it is on the chart borders.

asupriya
Advanced
Posts: 179
Joined: Mon Dec 01, 2008 12:00 am

Re: Resize chart with Selector Tool

Post by asupriya » Mon Jun 15, 2009 12:05 am

Also, Can you please provide an example of selector1.SelectableParts code?

Thanks,

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Resize chart with Selector Tool

Post by Sandra » Mon Jun 15, 2009 11:06 am

Hello asupriya,
How do I set the mouse cursor to double-diagonal arrow to indicate that border is resiable? Essentially, I like the mouse cursor to be reset to double headed arrow when it is on the chart borders.
We have added your request to the wish-list to be considered for inclusion in future releases.
Can you please provide an example of selector1.SelectableParts code?
I make a simple example:

InitializeChart:

Code: Select all

    Private Sub InitializeChart()
        FastLine1 = New Steema.TeeChart.Styles.FastLine(TChart1.Chart)
        FastLine1.FillSampleValues()
    End Sub
I have add selector to design time because is more simple to assigned the event.

Selected Event:

Code: Select all

   Private Sub Selector2_Selected(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Selector2.Selected
        Dim selectorPart As Steema.TeeChart.ChartClickedPart = New Steema.TeeChart.ChartClickedPart
        selectorPart = Selector2.Part
        If Not Selector2 Is Nothing Then
        End If
        If (selectorPart.Part = Steema.TeeChart.ChartClickedPartStyle.Series) Then

            TChart1.Legend.Visible = False
        ElseIf (selectorPart.Part = Steema.TeeChart.ChartClickedPartStyle.Axis) Then

            TChart1.Legend.Visible = True
        End If

    End Sub
I hope that will helps.

Thanks,
Best Regards,
Sandra Pazos / 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

asupriya
Advanced
Posts: 179
Joined: Mon Dec 01, 2008 12:00 am

Re: Resize chart with Selector Tool

Post by asupriya » Tue Jul 07, 2009 1:59 am

The new version works fine selector tool and all event handlers. Thanks.

The code sample for the selector1.SelectableParts you provided checks if the selected component is what I want and lets me do some events based on that. My requirement is that the selector should only appear when user selects the title or legend or the chart area; not the series or axis or anything else.

How do i "hide" selection for unwanted components so that users don't even get to selected a component that is not supposed to be selected.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Resize chart with Selector Tool

Post by Sandra » Tue Jul 07, 2009 9:43 am

Hello asupriya,

I make simple example that I think solve your problem. You want to use a similar code as next in your application.

Code: Select all

 Private fastline1 As Steema.TeeChart.Styles.FastLine
 Private selector1 As Steema.TeeChart.Tools.Selector

    Private Sub InitializeChart()
        fastline1 = New Steema.TeeChart.Styles.FastLine(tChart1.Chart)
        fastline1.FillSampleValues()
        selector1 = New Steema.TeeChart.Tools.Selector(tChart1.Chart)
        selector1.Cursor = Cursors.Hand
        selector1.AllowResizeChart = True
        selector1.Active = False
        AddHandler tChart1.MouseMove, AddressOf Me.tChart1_MouseMove
    End Sub
    Private Sub tChart1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
        Dim selectorPart As Steema.TeeChart.ChartClickedPart = New Steema.TeeChart.ChartClickedPart
        Dim rect As Rectangle = tChart1.Chart.ChartRect
        selectorPart = selector1.Part
        selector1.Active = False
        If tChart1.Header.Clicked(e.X, e.Y) Then
            selector1.Active = True
            selectorPart.Part = Steema.TeeChart.ChartClickedPartStyle.Header
        ElseIf (tChart1.Legend.Clicked(e.X, e.Y) <> -1) Then
            selector1.Active = True
            selectorPart.Part = Steema.TeeChart.ChartClickedPartStyle.Legend
        ElseIf rect.Contains(e.X, e.Y) Then
            selector1.Active = True
            selectorPart.Part = Steema.TeeChart.ChartClickedPartStyle.ChartRect
        Else
            selector1.Active = False
        End If
        If selector1.Active Then
            selector1.Part = selectorPart
        End If
    End Sub
I hope that will helps.
Best Regards,
Sandra Pazos / 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

asupriya
Advanced
Posts: 179
Joined: Mon Dec 01, 2008 12:00 am

Re: Resize chart with Selector Tool

Post by asupriya » Wed Jul 08, 2009 12:53 am

The code sample helps understand the Steema.TeeChart.ChartClickedPartStyle of the selector tool, but still doesn't show any way to achieve what I want.

Please see the code below. What I like to have is that users be able to select either chart title or legend or chart area (the rectangle described by tChart1.Chart.ChartBounds is needed - NOT tChart1.Chart.ChartRect) and be able to drag it. The following code behaves well with the legend and title dragging, but the tChart1.Chart.ChartBounds area (NOT tChart1.Chart.ChartRect) behaves in a weired way. It doesn't drag to exapnd or shrink the chart size. However, when mouse moves onto the chart bounds, the chart keeps shrinking to "infinity". I like to be able to drag the chart bounds to expand or shrink the chart size.

Please suggest some solution ASAP; now, its kind of urgent. Thanks.

Code: Select all

Public Class Form1
    Private WithEvents tChart1 As Steema.TeeChart.TChart
    Private WithEvents selector1 As Steema.TeeChart.Tools.Selector

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        tChart1 = New Steema.TeeChart.TChart
        tChart1.Dock = DockStyle.Top
        tChart1.Height = 300
        Me.Controls.Add(tChart1)

        Dim myFastLine As New Steema.TeeChart.Styles.FastLine(tChart1.Chart)
        myFastLine.DrawAllPoints = True 'Resolved this issue in latest version
        tChart1.Legend.Visible = False
        tChart1.Aspect.View3D = False
        myFastLine.FillSampleValues(18000)

        selector1 = New Steema.TeeChart.Tools.Selector(tChart1.Chart)
        selector1.Cursor = Cursors.Hand
        selector1.AllowResizeChart = True
        selector1.Active = False
        AddHandler tChart1.MouseMove, AddressOf tChart1_MouseMove
    End Sub
    Private Sub tChart1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
        Dim selectorPart As Steema.TeeChart.ChartClickedPart = New Steema.TeeChart.ChartClickedPart

        Dim rect As Rectangle = tChart1.Chart.ChartBounds 'tChart1.Chart.ChartRect

        selectorPart = selector1.Part
        selector1.Active = False
        If tChart1.Header.Clicked(e.X, e.Y) Then
            selector1.Active = True
            selectorPart.Part = Steema.TeeChart.ChartClickedPartStyle.Header
        ElseIf (tChart1.Legend.Clicked(e.X, e.Y) <> -1) Then
            selector1.Active = True
            selectorPart.Part = Steema.TeeChart.ChartClickedPartStyle.Legend
        ElseIf rect.Contains(e.X, e.Y) Then
            selector1.Active = True
            selectorPart.Part = Steema.TeeChart.ChartClickedPartStyle.ChartRect
        Else
            selector1.Active = False
        End If
        If selector1.Active Then
            selector1.Part = selectorPart
        End If
    End Sub
End Class

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Resize chart with Selector Tool

Post by Sandra » Wed Jul 08, 2009 10:24 am

Hello asupriya,

I modified your code, and now you can move the chart and change de size. and I think solved your problem. Please check next code works fine in your application.

Code: Select all

Public Class Form1
    Private WithEvents tChart1 As Steema.TeeChart.TChart
    Private WithEvents selector1 As Steema.TeeChart.Tools.Selector

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TChart1 = New Steema.TeeChart.TChart
        TChart1.Dock = DockStyle.Top
        TChart1.Height = 300
        TChart1.Legend.Visible = True
        Me.Controls.Add(TChart1)

        Dim myFastLine As New Steema.TeeChart.Styles.FastLine(tChart1.Chart)
        myFastLine.DrawAllPoints = True 'Resolved this issue in latest version
        TChart1.Legend.Visible = True
        tChart1.Aspect.View3D = False
        myFastLine.FillSampleValues(18000)

        selector1 = New Steema.TeeChart.Tools.Selector(tChart1.Chart)
        selector1.Cursor = Cursors.Hand
        selector1.AllowResizeChart = True
        selector1.Active = False
        AddHandler TChart1.MouseMove, AddressOf tChart1_MouseMove
        AddHandler TChart1.MouseDown, AddressOf TChart1_MouseDown
        AddHandler TChart1.MouseUp, AddressOf tChart1_MouseUp
    
        x = -1
        y = -1
        resizeW = False
        resizeH = False

    End Sub
    Private selectorPart As Steema.TeeChart.ChartClickedPart
    Private x, y As Integer
    Private resizeW, resizeH As Boolean
    Private xwidth, yheight As Integer

    Private Sub tChart1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
        selectorPart = New Steema.TeeChart.ChartClickedPart
        selectorPart = selector1.Part
        selector1.Active = False
        If tChart1.Header.Clicked(e.X, e.Y) Then
            selector1.Active = True
            selectorPart.Part = Steema.TeeChart.ChartClickedPartStyle.Header
        ElseIf (tChart1.Legend.Clicked(e.X, e.Y) <> -1) Then
            selector1.Active = True
            selectorPart.Part = Steema.TeeChart.ChartClickedPartStyle.Legend
        ElseIf (resizeW) Then
            TChart1.Width = TChart1.Width + (e.X - x)
            x = e.X
            TChart1.Refresh()
        ElseIf (resizeH) Then
            TChart1.Height = TChart1.Height + (e.Y - y)
            y = e.Y
            TChart1.Refresh()
        Else
            If ((x <> -1) And (y <> -1)) Then
                TChart1.Dock = DockStyle.None
                TChart1.Top = TChart1.Top + (e.Y - y)
                TChart1.Left = TChart1.Left + (e.X - x)
            End If
            selector1.Active = False
        End If

        If selector1.Active Then
            selector1.Part = selectorPart
        End If
    End Sub

    Private Sub tChart1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
        x = e.X
        y = e.Y

        If ((e.X <= TChart1.Width) And (e.X > TChart1.Width - 10)) Then
            resizeW = True
        End If

        If ((e.Y <= TChart1.Height) And (e.Y > TChart1.Height - 10)) Then
            resizeH = True
        End If

    End Sub

    Private Sub tChart1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
        x = -1
        y = -1

        resizeW = False
        resizeH = False
    End Sub
End Class
I hope that will helps,
Best Regards,
Sandra Pazos / 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

asupriya
Advanced
Posts: 179
Joined: Mon Dec 01, 2008 12:00 am

Re: Resize chart with Selector Tool

Post by asupriya » Thu Jul 09, 2009 5:55 am

Great!! It works.

Thank you very much.

Post Reply