Page 1 of 2

Drag-Drop onto custom Y-axis chart area

Posted: Thu Apr 15, 2010 5:32 am
by 13051032
I have a chart with multiple custom y-axis stacked vertically. If i want to implement a drag-drop event handler for the chart object such that when user drags a csv file onto an already displayed series with its own custom vertical y-axis, how do i go about it?

To make myself more clear, say, in the following code, I get 10 fast line series arranged vertically, say fs0 to fs9 series. Now, user drags and drops a csv file on the chart area covered by series fs6. I want to display the data such that both fs6 and new data shares the same vertical bounds (axis start and end positions of fs6) with same or new custom axis.

Can you please suggest?

Thanks,

Code: Select all

Imports Steema.TeeChart

Public Class Form1
    Private fs(128) As Steema.TeeChart.Styles.FastLine
    Private myAxis(128) As Steema.TeeChart.Axis

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized

        'Chart object
        Dim tchart1 As New Steema.TeeChart.TChart
        tchart1.Aspect.View3D = False
        tchart1.Dock = DockStyle.Fill
        tchart1.Aspect.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        tchart1.Aspect.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit

        'Now cursor tool
        Dim cursorTool1 As New Steema.TeeChart.Tools.CursorTool(tchart1.Chart)
        cursorTool1.FollowMouse = True
        cursorTool1.FastCursor = True
        cursorTool1.Pen.Style = System.Drawing.Drawing2D.DashStyle.Solid
        cursorTool1.Style = Steema.TeeChart.Tools.CursorToolStyles.Vertical
        cursorTool1.Pen.Color = Color.Orange
        cursorTool1.Pen.Width = 1

        'Now fast lines
        For i As Integer = 0 To 9
            'fastlines
            fs(i) = New Steema.TeeChart.Styles.FastLine(tchart1.Chart)
            fs(i).FillSampleValues(18000)
            fs(i).DrawAllPoints = False

            'axis
            If i = 0 Then
                myAxis(i) = tchart1.Chart.Axes.Left
                myAxis(i).StartEndPositionUnits = Steema.TeeChart.PositionUnits.Percent
                myAxis(i).StartPosition = 0
                myAxis(i).EndPosition = 10
                fs(i).VertAxis = Styles.VerticalAxis.Left
            Else
                myAxis(i) = New Steema.TeeChart.Axis(tchart1.Chart)
                myAxis(i).StartEndPositionUnits = Steema.TeeChart.PositionUnits.Percent
                tchart1.Axes.Custom.Add(myAxis(i))
                myAxis(i).StartPosition = myAxis(i - 1).EndPosition + 1
                myAxis(i).EndPosition = myAxis(i).StartPosition + 9
                fs(i).CustomVertAxis = myAxis(i)
            End If

        Next

        Dim myYAxis As New Steema.TeeChart.Axis
        tchart1.Axes.Custom.Add(myYAxis)
        myYAxis.Grid.Visible = False
        myYAxis.MinimumOffset = 15

        'fastline
        Dim fs2 As New Steema.TeeChart.Styles.FastLine(tchart1.Chart)
        fs2.FillSampleValues()
        fs2.DrawAllPoints = False
        fs2.CustomVertAxis = myYAxis
        myYAxis.StartPosition = 0
        myYAxis.EndPosition = 12
        'myYAxis.RelativePosition = -10
        myYAxis.StartEndPositionUnits = Steema.TeeChart.PositionUnits.Percent
        myYAxis.OtherSide = True
        Me.Controls.Add(tchart1)
    End Sub
End Class

Re: Drag-Drop onto custom Y-axis chart area

Posted: Fri Apr 16, 2010 8:52 am
by 10050769
Hi asupriya,

Shall I comment some things,

First, I understand that you want do, but I don't know if you would take cvs of directly Windows or directly of Visual Studios. Please, you could say exactly from where you want take file?

Second, when you have file, what are you want do with its information, for example:
- Add data in the area choose and created a new series.
-Add data to existing series.
-Remove existing data of area series and add file data in it.
-Etc.


Please, you could say exactly what are you doing with cvs file, when you charge it to area of TeeChart?

Thanks,

Re: Drag-Drop onto custom Y-axis chart area

Posted: Fri Apr 16, 2010 1:46 pm
by 13051032
Sandra,

1. I want to drag-drop at runtime - meaning from windows explorer to the application with tchart display - NOT from visual studio or not at the development time/design time.

2. When a file is drag-dropped, i want to create a new series in the way I described in the original post (in the chart area of, say, fs6) and associate this new series either to the same custom vertical axis or a new custom vertical axis.

3. I don't need to remove the existing series, but am interested to know if my users want to remove it, will it be difficult?

If you can respond before the end of the day, that will be appreciated.

Thanks

Re: Drag-Drop onto custom Y-axis chart area

Posted: Fri Apr 16, 2010 2:28 pm
by narcis
Hi asupriya,
1. I want to drag-drop at runtime - meaning from windows explorer to the application with tchart display - NOT from visual studio or not at the development time/design time.
In that case you'll need to find the code or the components to perform this task. I know of Raize's DropMaster but this is a Delphi and C++ Builder component. An option may be this:

http://tim.oreilly.com/pub/a/dotnet/200 ... agdrop.htm
2. When a file is drag-dropped, i want to create a new series in the way I described in the original post (in the chart area of, say, fs6) and associate this new series either to the same custom vertical axis or a new custom vertical axis.
I think it shouldn't be much complicated. Using mouse events on TeeChart you should be able to identify the chart area where you dropped the csv file as you already have axes IStartPos and IEndPos. Then you will just need to create a series, associate the series to corresponding axes and assign csv file as series' datasource.
3. I don't need to remove the existing series, but am interested to know if my users want to remove it, will it be difficult?
No, you could search for series associated to relevant axis, looping through chart's series collection, and remove them.

Hope this helps!

Re: Drag-Drop onto custom Y-axis chart area

Posted: Fri Apr 16, 2010 2:36 pm
by 13051032
Narcis,

drag-drop is not my problem and i already implemented it. the issue is how to find the chart area that is dropped on. When i do drag-drop, chart's drag-drop event is triggered, but need to know how to get the start and end position of the custom y-axis that corresponds to dropped area.

Can you give some sample code?

Thanks

Re: Drag-Drop onto custom Y-axis chart area

Posted: Fri Apr 16, 2010 2:46 pm
by narcis
Hi asupriya,

In that case, in the DragDrop event you already have e.X and e.Y arguments. You should search among your axes which occupies the range comprising e.Y, for example:

Code: Select all

		void tChart1_DragDrop(object sender, DragEventArgs e)
		{
			for (int i = 0; i < tChart1.Axes.Custom.Count; i++)
			{
				Steema.TeeChart.Axis a = tChart1.Axes.Custom[i];

				if ((! a.Horizontal) && (a.IStartPos <= e.Y) && (a.IEndPos <= e.Y))
				{
					tChart1.Series.Add(new Steema.TeeChart.Styles.FastLine());
					tChart1[tChart1.Series.Count - 1].CustomVertAxis = a;
					//Assign csv as series datasource here.
				}
			}
		}

Re: Drag-Drop onto custom Y-axis chart area

Posted: Tue Apr 20, 2010 5:00 am
by 13051032
The sample code you provided has an issue. The istartpos and iendpos values are relative to the chart (value 100 is 100 pixels down from the x-axis of that chart where as the mouse coordinates from drag-drop event are screen coordinates. How can i make them consistent?

Re: Drag-Drop onto custom Y-axis chart area

Posted: Wed Apr 21, 2010 10:51 am
by narcis
Hi asupriya,

What about this?

Code: Select all

        void tChart1_DragDrop(object sender, DragEventArgs e)
        {
            for (int i = 0; i < tChart1.Axes.Custom.Count; i++)
            {
                Steema.TeeChart.Axis a = tChart1.Axes.Custom[i];
                Rectangle rect = tChart1.Chart.ChartRect;

                if ((!a.Horizontal) && (a.IStartPos + rect.Top <= e.Y) && (a.IEndPos + rect.Top <= e.Y))
                {
                    tChart1.Series.Add(new Steema.TeeChart.Styles.FastLine());
                    tChart1[tChart1.Series.Count - 1].CustomVertAxis = a;
                    //Assign csv as series datasource here.
                }
            }
        }

Re: Drag-Drop onto custom Y-axis chart area

Posted: Wed Apr 21, 2010 7:11 pm
by 13051032
This doesn't help either, especially when you have chart rect size large enough (with multiple custom y-axis stacked vertically) to get a scroll bar.

Really appreciate if you provide a working example.

Re: Drag-Drop onto custom Y-axis chart area

Posted: Thu Apr 22, 2010 11:19 am
by 10050769
Hello asupriya,

Please, you could send us a project, because we can find a good solution for your problem? You could attach your project directly in this thread.

Thanks,

Re: Drag-Drop onto custom Y-axis chart area

Posted: Fri Apr 23, 2010 1:51 am
by 13051032
Please find the code that does everything at runtime. Please create a blank vb .net project and paste this code.

At runtime, Make sure you generate enough custom vertical axes to have the windows form a scroll bar. Then, scroll down to the last custom axis and try to drag-drop any file on the chart. You will get a wrong axis handler with the Narcis suggested code.

Please suggest something so that I always get correct custom axis regardless of scroll positions, etc.

Really appreciate if you can help me resolve this issue before the weekend.

Thanks,

Code: Select all

Imports Steema.TeeChart

Public Class Form1
    Private fs(128) As Steema.TeeChart.Styles.FastLine
    Private myAxis(128) As Steema.TeeChart.Axis
    Private WithEvents tchart1 As Steema.TeeChart.TChart

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
        Me.AutoScroll = True

        'Chart object
        tchart1 = New Steema.TeeChart.TChart
        tchart1.AllowDrop = True
        tchart1.Aspect.View3D = False
        tchart1.Dock = DockStyle.Top
        tchart1.Aspect.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        tchart1.Aspect.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit

        'Now cursor tool
        Dim cursorTool1 As New Steema.TeeChart.Tools.CursorTool(tchart1.Chart)
        cursorTool1.FollowMouse = True
        cursorTool1.FastCursor = True
        cursorTool1.Pen.Style = System.Drawing.Drawing2D.DashStyle.Solid
        cursorTool1.Style = Steema.TeeChart.Tools.CursorToolStyles.Vertical
        cursorTool1.Pen.Color = Color.Orange
        cursorTool1.Pen.Width = 1
        tchart1.Panel.MarginLeft = 30

        'Now fast lines
        For i As Integer = 0 To 50
            'fastlines
            fs(i) = New Steema.TeeChart.Styles.FastLine(tchart1.Chart)
            fs(i).FillSampleValues(18000)
            fs(i).DrawAllPoints = False
            tchart1.Height += 56

            'axis
            If i = 0 Then
                myAxis(i) = New Steema.TeeChart.Axis(tchart1.Chart) ' tchart1.Chart.Axes.Left
                myAxis(i).StartEndPositionUnits = Steema.TeeChart.PositionUnits.Pixels
                myAxis(i).StartPosition = 0
                myAxis(i).EndPosition = 55
                myAxis(i).Title.Text = "Axis_" & i
                myAxis(i).Title.TextAlign = StringAlignment.Near
                myAxis(i).Automatic = True
                fs(i).CustomVertAxis = myAxis(i)
                tchart1.Axes.Custom.Add(myAxis(i))
            Else
                myAxis(i) = New Steema.TeeChart.Axis(tchart1.Chart)
                myAxis(i).Title.Text = "Axis_" & i
                myAxis(i).Title.TextAlign = StringAlignment.Near
                myAxis(i).Automatic = True
                myAxis(i).StartEndPositionUnits = Steema.TeeChart.PositionUnits.Pixels
                tchart1.Axes.Custom.Add(myAxis(i))
                myAxis(i).StartPosition = myAxis(i - 1).EndPosition + 5
                myAxis(i).EndPosition = myAxis(i).StartPosition + 50
                fs(i).CustomVertAxis = myAxis(i)
            End If
        Next

        Me.Controls.Add(tchart1)
    End Sub

    Private Sub tchart1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles tchart1.DragDrop
        Dim rect As Rectangle = CType(sender, Steema.TeeChart.TChart).Chart.ChartRect
        Dim dragDropAxis As Steema.TeeChart.Axis

        For i As Integer = 0 To CType(sender, Steema.TeeChart.TChart).Axes.Custom.Count - 1
            dragDropAxis = CType(sender, Steema.TeeChart.TChart).Axes.Custom(i)
            If (Not dragDropAxis.Horizontal) And (((dragDropAxis.IStartPos + rect.Top) <= e.Y) AndAlso ((dragDropAxis.IEndPos + rect.Top) >= e.Y)) Then
                MsgBox("Dropped on " & dragDropAxis.Title.Text)
                Exit For
            End If
        Next
    End Sub

    Private Sub tchart1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles tchart1.DragEnter
        If e.Data.GetDataPresent("FileDrop") Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub
End Class

Re: Drag-Drop onto custom Y-axis chart area

Posted: Mon Apr 26, 2010 6:23 pm
by 13051032
Can someone help me out here please? Its a while I have been waiting for a working solution.

Thanks

Re: Drag-Drop onto custom Y-axis chart area

Posted: Tue Apr 27, 2010 1:47 pm
by 13051032
Steema Support,

I have been waiting for this issue resolution for past two working days. Can someone help me with this issue?

Re: Drag-Drop onto custom Y-axis chart area

Posted: Tue Apr 27, 2010 3:18 pm
by narcis
Hello asupriya,

Have you tried looking for alternatives similar to what I suggested? Considering form dimensions or chart dimensions instead? If this doesn't help we will look into your issue ASAP. If you are interested in prioritary support you may be interested in checking out our Pro-Support service.

Re: Drag-Drop onto custom Y-axis chart area

Posted: Wed Apr 28, 2010 4:24 am
by 13051032
I tried all the alternatives similar to what you suggested. All these techniques works well as long as you the number of custom-y-axes count is small enough so that user doesn't need to scroll down. All these techniques fail once the user scrolls down to the last axis near the bottom x-axis.

That is why i need a solution that reliably works for scrolled scenarios and normal scenarios as well.

BTW, I requested my manager to consider buying the premium support and will see what they decide.