Dynamically generating the charts

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

Dynamically generating the charts

Post by asupriya » Wed Dec 10, 2008 7:38 pm

Hi,

Please see the prior communication below by scrolling down. I am posting here for prompt reply.

When i use
Panel2.Controls.Add(TChart1) to define parent for the chart, i get the following compilation error. It could be because i am defining these charts as an array of Chart objects and the size of the array of these Chart objects is defined at runtime (after reading certain parameters from a file). So, I am not able to use 'Withevents' for the Chart as the VS 2005 complaining that 'Withevents' can not be used with array of objects.
If i try to create individual chart objects within the calling function, compiler says that i can not use 'Withevents' with the local variables.

So, the real question is how can i define as many chart objects as i need at the runtime. If you have any example code, please share.

Error 1 Value of type 'Steema.TeeChart.Chart' cannot be converted to
'System.Windows.Forms.Control'.
-Prototype\Form1.vb
101 40 TeeChart-Prototype

Please suggest what i should do.

Thanks,
Supriya

From: "Narcís Calvet" <support@steema.com>
Newsgroups: steema.private.support.teechart.dotnet
Sent: Wednesday, December 10, 2008 2:19 AM
Subject: Re: Dynamically generating charts



>
> Try this:
>
> Panel2.Controls.Add(TChart1)
>
> Hope this helps!
>
>
> --
> Best Regards,
>
> Narcís Calvet
> Steema Support Central
> http://support.steema.com
>
> "Important note: If you are a TeeChart registered customer, please post
> your support questions at Steema's Support monitored Forums for customers:
> http://support.steema.com for a prompter reply."
>
>
> <asupriya@xxx.xxx> wrote in message
> news:Pa%23NYYpWJHA.1896@TEEPC.Steema.local...
>> Hi,
>> I need to generate charts dynamically based on the parameters that is
>> read from a file. When i tried to do it in the following way, I get an
>> error at at the .parent setup property. Can you please help me?
>>
>> Below is my code. ChartLegends is an array of legends to be posted. There
>> needs to be one series per chart and each series should be present in the
>> legend.
>>
>> Thanks,
>> Supriya
>>
>> For i = 0 To chartLegends.Length - 2
>>
>> myFastLine(i) = New Steema.TeeChart.Styles.FastLine
>>
>> TChart1(i) = New Chart
>>
>> TChart1(i).Page.MaxPointsPerPage = 1000
>>
>> TChart1(i).Page.ScaleLastPage = False
>>
>> 'Me.Panel2.Controls.Add(Me.TChart1(i))
>>
>> 'Panel2 = CType(Panel2, Steema.TeeChart.IChart)
>>
>> TChart1(i).Parent = Panel2
>>
>> TChart1(i).Width = Panel2.Width
>>
>> TChart1(i).Height = 100
>>
>> 'TChart1(i).Page.Current = 0
>>
>> myFastLine(i).Title = chartLegends(i + 1)
>>
>> myFastLine(i).ColorEach = True
>>
>> 'myFastLine(i).Color = Color.FromArgb(333 * i)
>>
>> TChart1(i).Series.Add(myFastLine(i))
>>
>> myFastLine(i).DrawAllPoints = True
>>
>> 'myFastLine(i).TreatNulls =
>> Steema.TeeChart.Styles.TreatNullsStyle.Skip
>>
>> Next
>>
>>
>
>
Last edited by asupriya on Sat Jun 20, 2009 4:17 pm, edited 1 time in total.

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 Dec 11, 2008 10:26 am

Hi Supriya,

In that case you can do something like this:

Code: Select all

Public Class Form1


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitializeChart()
    End Sub

    Private WithEvents MyChart As Steema.TeeChart.TChart
    Private panels() As Panel = New Panel(5) {}

    Private Sub InitializeChart()

        For i As Integer = 0 To panels.Length - 1
            panels(i) = New Panel

            MyChart = New Steema.TeeChart.TChart()

            Me.Controls.Add(panels(i))
            panels(i).Location = New Point(150 * i, 0)
            panels(i).Width = 150
            panels(i).Height = 100
            panels(i).Controls.Add(MyChart)

            MyChart.Dock = DockStyle.Fill

            MyChart.Series.Add(New Steema.TeeChart.Styles.Line())
            MyChart(0).FillSampleValues()

            AddHandler MyChart.AfterDraw, AddressOf MyChart_AfterDraw

            'You can typecast panel's controls like this:
            CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Legend.Visible = False
            CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Header.Visible = False
        Next

    End Sub

    Private Sub MyChart_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D)
        g.TextOut(20, 10, "hello!")
    End Sub

End Class
Hope this helps!
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

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

Post by asupriya » Thu Dec 11, 2008 2:42 pm

Great. this is what i wanted.

Thanks for the help.

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

Post by asupriya » Fri Dec 12, 2008 5:40 am

One more issue.

My file typically contains 5000 milli seconds worth of data with 10 ms interval for various frequency. This gives a huge number of points for each of the frequency.

I plan to use the fastline series; but, i need to provide a long scrollable chart for the user to look at the data (possibly each point) and scrolls the chart (not paging the chart, but actually scrolling the chart data) to see more.

Can you suggest me how i can set the chart dimensions such that my charts are displayed with enough details and with automatic Horizontal scroll bars? When i try to set the dock property of the chart to 'Fill' to the panel and set the panel's dock property 'Fill' to the form, i am getting a very squeezed display that displays 0ms to 5000ms in the width of the form without the scroll bars.

Any suggestions will be appreciated.

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 12, 2008 9:51 am

Hi asupriya,

You can get the number of points displayed in a chart like this I explained here:

http://www.teechart.net/support/viewtopic.php?t=8931

You can use horizontal scrollbar like in the example Pep posted on this thread:

http://www.teechart.net/support/viewtopic.php?t=1924

Please bear in mind that the maximum rate of points that can be drawn is one point per pixel so you may also want to check ChartRect's dimensions:

Code: Select all

			tChart1.Draw();
			Rectangle rect = tChart1.Chart.ChartRect;
			int w = rect.Width;
			int h = rect.Height;
Finally you may also be interested in DownSampling function as shown in the All Features\Welcome !\Functions\Extended\Reducing number of points in the features demo, available at TeeChart's program group. It may be also worth having a look at the All Features\Welcome !\Speed\Fast Line Speed DrawAll

Hope this helps!
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

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

Post by asupriya » Sat Dec 13, 2008 6:20 am

Thanks alot for the suggestions.

Is there anyway i can access the chart objects that are dynamically created as you suggested above? I need to optionally synchronize the curserTool objects on each of these charts (as shown in the Welcome !\Tools\Cursor\Synchronizing Two example).

Also, these chart objects are arranged vertically and I need to align all of them such that their X-values are perfectly aligned vertically. When i set myChart.position to have same X position, its aligning not the y-axis so that X-values get aligned. This problem becomes obvious when you have different Y-axis value range on each of the charts (for example chart 1 with two digit values, chart 2 has 4-digit values, it will push the y-axis to the right on the chart 2).

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

Post by Narcís » Mon Dec 15, 2008 9:35 am

Hi asupryia,

Yes, you can use them as shown in the example I posted, I also extended it with CursorTool:

Code: Select all

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitializeChart()
    End Sub

    Private WithEvents MyChart As Steema.TeeChart.TChart
    Private panels() As Panel = New Panel(5) {}

    Private Sub InitializeChart()

        For i As Integer = 0 To panels.Length - 1
            panels(i) = New Panel

            MyChart = New Steema.TeeChart.TChart()

            Me.Controls.Add(panels(i))
            panels(i).Location = New Point(150 * i, 0)
            panels(i).Width = 150
            panels(i).Height = 100
            panels(i).Controls.Add(MyChart)

            MyChart.Dock = DockStyle.Fill

            MyChart.Series.Add(New Steema.TeeChart.Styles.Line())
            MyChart(0).FillSampleValues()

            AddHandler MyChart.AfterDraw, AddressOf MyChart_AfterDraw

            'You can typecast panel's controls like this:
            CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Legend.Visible = False
            CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Header.Visible = False

            Dim MyCursor As New Steema.TeeChart.Tools.CursorTool(MyChart.Chart)

            CType(CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Tools.Item(0),  _
                    Steema.TeeChart.Tools.CursorTool).XValue = 5
            CType(CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Tools.Item(0),  _
                    Steema.TeeChart.Tools.CursorTool).YValue = 5
            CType(CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Tools.Item(0),  _
                    Steema.TeeChart.Tools.CursorTool).XValue = 5
        Next

    End Sub

    Private Sub MyChart_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D)
        g.TextOut(20, 10, "hello!")
    End Sub
About aligning charts, please read this:

http://www.teechart.net/support/viewtopic.php?t=3034

Hope this helps!
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

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

Post by asupriya » Tue Dec 16, 2008 3:24 am

Thanks.

I have at least 15 chart objects (there can be as many as 128 chart objects in the worst case scenario) to sync the cursor. CType'ing every time is VERY very slow and after about 5 charts, the performance is almost unacceptable.

Is there any other way of keeping track of these chart objects?

regards

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

Post by Narcís » Tue Dec 16, 2008 12:57 pm

Hi asupriya,

Of course, you could also access CursorTools directly:

Code: Select all

    Private Sub InitializeChart()

        For i As Integer = 0 To panels.Length - 1
            panels(i) = New Panel

            MyChart = New Steema.TeeChart.TChart()

            Me.Controls.Add(panels(i))
            panels(i).Location = New Point(150 * i, 0)
            panels(i).Width = 150
            panels(i).Height = 100
            panels(i).Controls.Add(MyChart)

            MyChart.Dock = DockStyle.Fill

            MyChart.Series.Add(New Steema.TeeChart.Styles.Line())
            MyChart(0).FillSampleValues()

            AddHandler MyChart.AfterDraw, AddressOf MyChart_AfterDraw

            ''You can typecast panel's controls like this:
            'CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Legend.Visible = False
            'CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Header.Visible = False

            MyChart.Legend.Visible = False
            MyChart.Header.Visible = False

            Dim MyCursor As New Steema.TeeChart.Tools.CursorTool(MyChart.Chart)

            MyCursor.XValue = 5
            MyCursor.YValue = 5
            MyCursor.XValue = 5

            'CType(CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Tools.Item(0),  _
            '        Steema.TeeChart.Tools.CursorTool).XValue = 5
            'CType(CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Tools.Item(0),  _
            '        Steema.TeeChart.Tools.CursorTool).YValue = 5
            'CType(CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Tools.Item(0),  _
            '        Steema.TeeChart.Tools.CursorTool).XValue = 5
        Next

    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

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

Post by asupriya » Tue Dec 16, 2008 1:56 pm

I should have been more specific.

I already assign the cursortool in the way you suggested. However, the problem is during the cursorTool1.Change event handling. My code is as follows. It takes about 20-30 sec to change surser position on all the 15 charts. Please suggest a better alternative.

Code: Select all

 Private Sub cursorTool1_Change(ByVal sender As Object, ByVal e As Steema.TeeChart.Tools.CursorChangeEventArgs) Handles cursorTool1.Change
        ChartStatusLbl.Text = "Time = " & e.XValue & " Y = " & e.YValue

        Dim i As Int32

        For i = 0 To numCharts - 1
            CType(CType(Panel2.Controls.Item(i), Steema.TeeChart.TChart).Tools.Item(0), Steema.TeeChart.Tools.CursorTool).XValue =e.XValue
        Next
             
    End Sub
Couple more questions:

1. I am experimenting with the same data used in the dynamic generation of each chart for each of the data series with single chart and multiple custom left axis option. Each of the series has its own custom left axis on a single chart object. The intention is that this method would be much more faster than the previous method where you generate as many charts as the distinct series. But, to my surprise, this method of single chart with multiple custom left charts is much slower than the multiple charts method (keeping the rest all the same - series, data, etc.). Can you please comment on it? Below is the snippet of code.

Code: Select all

If (br.BaseStream.Position = data.endptr) Then

                        ReDim chartLegends(numCharts - 1)
                        ReDim myFastLine(numCharts - 1)
                        Dim chartWidth As Int32 = (br.BaseStream.Length - br.BaseStream.Position) / 4 ' 4-byte short
                        Dim chartOffset As Int16 = 0

                        'Define chart properties
                        MyChart = New Steema.TeeChart.TChart()
                        MyChart.Legend.Visible = False
                        MyChart.Aspect.View3D = False
                        MyChart.Legend.LegendStyle = Steema.TeeChart.LegendStyles.Series
                        MyChart.Legend.Alignment = Steema.TeeChart.LegendAlignments.Right
                        MyChart.Width = 2000 'chartWidth / 10
                        MyChart.Height = numCharts * 150 'each axis is 150 pixel height
                        MyChart.Header.Text = ""
                        MyChart.Axes.Left.EndPosition = 0

                        MyChart.Panel.MarginTop = 0
                        MyChart.Panel.MarginBottom = 0
                        MyChart.Axes.Left.Labels.CustomSize = 60

                        MyChart.Axes.Left.MinimumOffset = 10
                        MyChart.Axes.Left.MaximumOffset = 10
                        MyChart.Axes.Bottom.MinimumOffset = 10
                        MyChart.Axes.Bottom.MaximumOffset = 10
                        MyChart.Aspect.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
                        MyChart.Aspect.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit

                        Panel2.Controls.Add(MyChart)
                        
                        Dim myStartPos As Double = 0.5
                        Dim myChartSize As Double = (100 / numCharts) - 1

                        For i = 0 To numCharts - 1
                            
                            axis1 = New Steema.TeeChart.Axis(MyChart.Chart) ' define an axis for this series
                            MyChart.Axes.Custom.Add(axis1)
                            axis1.Horizontal = False
                            axis1.OtherSide = False
                            axis1.Labels.CustomSize = 100
                            axis1.Title.Angle = 90
                            axis1.Title.Caption = chartLegends(i)
                            axis1.StartPosition = myStartPos 
                            axis1.EndPosition = (myStartPos + myChartSize) Mod 100
                            myStartPos += (myChartSize + 0.4)

                            cursorTool1 = New Steema.TeeChart.Tools.CursorTool()
                            cursorTool1.FollowMouse = True
                            cursorTool1.Active = True
                            cursorTool1.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dash
                            cursorTool1.Style = Steema.TeeChart.Tools.CursorToolStyles.Vertical
                            cursorTool1.Pen.Color = Color.DarkGreen

                            MyChart.Tools.Add(cursorTool1)
                            AddHandler cursorTool1.Change, AddressOf cursorTool1_Change

                            myFastLine(i) = New Steema.TeeChart.Styles.FastLine
                            myFastLine(i).DrawAllPoints = True
                            myFastLine(i).CustomVertAxis = axis1
                            cursorTool1.Series = myFastLine(i)
                            myFastLine(i).Title = chartLegends(i)
                            MyChart.Series.Add(myFastLine(i))
                        Next
end if
2. Other question is: How can i change the thickness of the myfastline(i) in the above code?

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 Dec 17, 2008 12:26 pm

Hi asupriya,
I already assign the cursortool in the way you suggested. However, the problem is during the cursorTool1.Change event handling. My code is as follows. It takes about 20-30 sec to change surser position on all the 15 charts. Please suggest a better alternative.
Using code below, building the applicaiton in release mode and running application's .exe it takes between 55 and 90 milliseconds updating all cursors using latest TeeChart for .NET v3 release available in an Intel Core 2 Quad 6600 machine with 4 GB RAM and a nVidia GeForce 8500 GT graphic card.

Could you please try running code below and let us know how it goes at your end and also let us know the environment you are using?

Also, if you uncomment the MyCursor.FastCursor = True line the application is even faster as no chart redraw is necessary.

Code: Select all

Imports System.IO

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitializeChart()
    End Sub

    Private WithEvents MyChart As Steema.TeeChart.TChart
    Private WithEvents MyCursor As New Steema.TeeChart.Tools.CursorTool
    Private WithEvents TChart1 As Steema.TeeChart.TChart
    Private WithEvents CursorTool1 As New Steema.TeeChart.Tools.CursorTool
    Private Label1 As Label
    Private panels() As Panel = New Panel(15) {}
    Private stopWatch As System.Diagnostics.Stopwatch

    Private Sub InitializeChart()

        Dim w As Integer = 150
        Dim h As Integer = 100

        For i As Integer = 0 To panels.Length - 1
            panels(i) = New Panel

            MyChart = New Steema.TeeChart.TChart()

            Me.Controls.Add(panels(i))
            panels(i).Location = New Point(w * (i Mod 5), h * (i Mod 3))
            panels(i).Width = w
            panels(i).Height = h
            panels(i).Controls.Add(MyChart)

            MyChart.Dock = DockStyle.Fill

            MyChart.Series.Add(New Steema.TeeChart.Styles.FastLine())
            MyChart(0).FillSampleValues()
            MyChart(0).Color = Color.DarkBlue

            MyChart.Legend.Visible = False
            MyChart.Header.Visible = False

            MyCursor = New Steema.TeeChart.Tools.CursorTool(MyChart.Chart)
            'MyCursor.FastCursor = True

            MyCursor.XValue = 5
            MyCursor.YValue = 5
            MyCursor.XValue = 5
        Next

        TChart1 = New Steema.TeeChart.TChart()
        Me.Controls.Add(TChart1)
        TChart1.Location = New Point(0, h * 3)

        Dim FastLine1 As New Steema.TeeChart.Styles.FastLine(TChart1.Chart)
        FastLine1.Color = Color.Red
        FastLine1.LinePen.Width = 3
        FastLine1.FillSampleValues()

        CursorTool1 = New Steema.TeeChart.Tools.CursorTool(TChart1.Chart)
        CursorTool1.Style = Steema.TeeChart.Tools.CursorToolStyles.Vertical
        CursorTool1.FollowMouse = True

        AddHandler CursorTool1.Change, AddressOf cursorTool1_Change

        Label1 = New Label
        Me.Controls.Add(Label1)
        Label1.Location = New Point(TChart1.Width + 10, TChart1.Location.Y + 100)
        Label1.AutoSize = True

        Me.Width = w * 5
        Me.Height = h * 3 + TChart1.Height

        stopWatch = New System.Diagnostics.Stopwatch()

        AddHandler CType(panels(0).Controls.Item(0), Steema.TeeChart.TChart).BeforeDraw, AddressOf MyChart_BeforeDraw
        AddHandler CType(panels(panels.Length - 1).Controls.Item(0), Steema.TeeChart.TChart).AfterDraw, AddressOf MyChart_AfterDraw
    End Sub

    Private Sub cursorTool1_Change(ByVal sender As Object, ByVal e As Steema.TeeChart.Tools.CursorChangeEventArgs)
        Dim i As Int32

        For i = 0 To panels.Length - 1
            CType(CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Tools.Item(0), Steema.TeeChart.Tools.CursorTool).XValue = e.XValue
        Next
    End Sub

    Private Sub MyChart_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D)
        stopWatch.Stop()

        Dim elapsedTime As TimeSpan = stopWatch.Elapsed
        Label1.Text = "Elapsed time: " + elapsedTime.TotalMilliseconds.ToString() + " ms"
    End Sub

    Private Sub MyChart_BeforeDraw(ByVal sender As System.Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D)
        stopWatch.Reset()
        stopWatch.Start()
    End Sub
End Class
1. I am experimenting with the same data used in the dynamic generation of each chart for each of the data series with single chart and multiple custom left axis option. Each of the series has its own custom left axis on a single chart object. The intention is that this method would be much more faster than the previous method where you generate as many charts as the distinct series. But, to my surprise, this method of single chart with multiple custom left charts is much slower than the multiple charts method (keeping the rest all the same - series, data, etc.). Can you please comment on it? Below is the snippet of code.
Could you please arrange an example similar to the one above so that we can reproduce the issue here?

You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.

2. Other question is: How can i change the thickness of the myfastline(i) in the above code?
Try this:

Code: Select all

                            myFastLine(i).LinePen.Width = 3
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

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

Post by asupriya » Thu Dec 18, 2008 6:06 am

Thanks. Your machine is very high end. We are developing for a "typical" machine configuration with around 512 MB RAM, >2GHz processor, and "average" video card. I will try and let you know the time for the code you posted.

The delay (in custom left axis scenario) is not really in chart generation, but in the display/paint. When i debugged earlier (without stopwatch), all the chart instantiation and series population gets done in "reasonable" amount of time, but the final display (probably draw/paint call) takes long time to show up. I will get you the actual numbers probably today or so. It could be my graphics card (Intel 82852/82855 GM/GME Graphics card with 64 MB video RAM) that is the root cause of these issues.

Reg. the cursortool1.change event, i continue to have same problem of delay in cursor updates. With fastcusor set to true, the charts are marked with random lines in the direction of mouse movement (probably graphics card issue). I will create a test project in a day or so and upload it for your reference.

Here are some more questions i have:

1. I defined this cursortool1.change event and get the e.xvalue and e.yvalue posted in the status bar. Now, i also activated Mark-tip tool for each of the series. There is a slight difference of values for the same cursor position in the cursortool1.event's e.xvalue and the Mark-tip tool's display with Steema.TeeChart.Styles.MarksStyles.XY style. The difference is in the digits after the decimal. e.yvalue matches with the mark-tip value. Also sometimes, the comma between the X and Y values doesn't showup. I am wondering which is more accurate and why such a variation.

2. Just as synchronized cursors, i like to optionally sync the zoom and scroll activities as well across different charts we dynamically create. I defined the handler as follows. But, i am not sure how i can access the user created zoom rectangle and pass it to other chart objects. Please suggest how i should proceed.

3. My charts are each 150 pixels in height. When printing one chart, i like to magnify it to occupy full page in landscape mode. I tried to set the margins and played with the other settings, but could not figureout how to magnify the chart to "fit the page" so that it will be legible. I have a long chart (chart.width=2000) and like to print it into several pages with legible chart, labels, and series data. Please suggest.

4. Now, i also want to print about three of the above generated charts into one page. As you can see, each chart is generated separately, but while printing, i like to club them so that user can choose which three charts go into a common print job on a single sheet (with possible magnification as needed in point 3). Please suggest how i should proceed.

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 Dec 18, 2008 10:17 am

Hi asupriya,
Thanks. Your machine is very high end. We are developing for a "typical" machine configuration with around 512 MB RAM, >2GHz processor, and "average" video card. I will try and let you know the time for the code you posted.
Using powerful machines we make our work faster and I guess we are more productive that way :wink:.
The delay (in custom left axis scenario) is not really in chart generation, but in the display/paint. When i debugged earlier (without stopwatch), all the chart instantiation and series population gets done in "reasonable" amount of time, but the final display (probably draw/paint call) takes long time to show up. I will get you the actual numbers probably today or so. It could be my graphics card (Intel 82852/82855 GM/GME Graphics card with 64 MB video RAM) that is the root cause of these issues.
If you can it would be good that you made the tests in different machine configurations so that you can compare results.
Reg. the cursortool1.change event, i continue to have same problem of delay in cursor updates. With fastcusor set to true, the charts are marked with random lines in the direction of mouse movement (probably graphics card issue). I will create a test project in a day or so and upload it for your reference.
I can't reproduce this here.
1. I defined this cursortool1.change event and get the e.xvalue and e.yvalue posted in the status bar. Now, i also activated Mark-tip tool for each of the series. There is a slight difference of values for the same cursor position in the cursortool1.event's e.xvalue and the Mark-tip tool's display with Steema.TeeChart.Styles.MarksStyles.XY style. The difference is in the digits after the decimal. e.yvalue matches with the mark-tip value. Also sometimes, the comma between the X and Y values doesn't showup. I am wondering which is more accurate and why such a variation.
MarksTip tool displays the exact value of each point in the series. While CursorTool's values and they may not be in the very same point as series values.

Regarding the comma between X and Y issue in MarksTip, by default it's not displayed. You can customize mark text using GetMarkText event or MarksTip's GetText event.
2. Just as synchronized cursors, i like to optionally sync the zoom and scroll activities as well across different charts we dynamically create. I defined the handler as follows. But, i am not sure how i can access the user created zoom rectangle and pass it to other chart objects. Please suggest how i should proceed.
You should use Zoomed, UndoneZoom and Scroll events to retrieve zoomed/scrolled chart axes min. and max. values and set them to the other charts using axis SetMinMax method.
3. My charts are each 150 pixels in height. When printing one chart, i like to magnify it to occupy full page in landscape mode. I tried to set the margins and played with the other settings, but could not figureout how to magnify the chart to "fit the page" so that it will be legible. I have a long chart (chart.width=2000) and like to print it into several pages with legible chart, labels, and series data. Please suggest.
You can do as shown here:

http://www.teechart.net/support/viewtopic.php?t=4305

You may also be interessed in those threads:

http://www.teechart.net/support/viewtopic.php?t=5490
http://www.teechart.net/support/viewtopic.php?t=3424
4. Now, i also want to print about three of the above generated charts into one page. As you can see, each chart is generated separately, but while printing, i like to club them so that user can choose which three charts go into a common print job on a single sheet (with possible magnification as needed in point 3). Please suggest how i should proceed.
What I told in previous answer should help you on setting charts dimension. As far as printing mulitple charts you can have a look here:

http://www.teechart.net/support/viewtopic.php?t=5756
http://www.teechart.net/support/viewtopic.php?t=1883

Hope this helps!
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

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

Post by asupriya » Fri Dec 19, 2008 5:21 am

1.
You should use Zoomed, UndoneZoom and Scroll events to retrieve zoomed/scrolled chart axes min. and max. values and set them to the other charts using axis SetMinMax method.
Can you please show some sample code with two dynamically generated charts sync'ing for zoom and scroll? I don't know how to get the user defined rectangle for the zoom action.

Printing with large plot and paper size works like charm. Thanks. I need to spend some time to do the multi-chart part as well.

2. I need similar functionality as shown in the .Net examples (You need to search the Example Demo with keyword "Enable Functions" and you get only one hit) that enables users to click on the series to change its color. Along with the color, i need to be able to change all pen properties. I need such a functionality when user double-clicks on the legend of a fastline series. I looked in the demo code for this demo, but couldn't really follow how i can capture a click event for a dynamically generated series and its legend.

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 19, 2008 10:39 am

Hi asupriya,
Can you please show some sample code with two dynamically generated charts sync'ing for zoom and scroll? I don't know how to get the user defined rectangle for the zoom action.
You should do something as what I suggested here.

I have applied that to dynamic charts in the example below.
Printing with large plot and paper size works like charm. Thanks. I need to spend some time to do the multi-chart part as well.
I'm glad to hear that.
2. I need similar functionality as shown in the .Net examples (You need to search the Example Demo with keyword "Enable Functions" and you get only one hit) that enables users to click on the series to change its color. Along with the color, i need to be able to change all pen properties. I need such a functionality when user double-clicks on the legend of a fastline series. I looked in the demo code for this demo, but couldn't really follow how i can capture a click event for a dynamically generated series and its legend.
Ok, I've also added this feature to the example below using PenEditor and ClickLegend event.

Code: Select all

Imports System.IO

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitializeChart()
    End Sub

    Private WithEvents MyChart As Steema.TeeChart.TChart
    Private WithEvents MyCursor As New Steema.TeeChart.Tools.CursorTool
    Private WithEvents TChart1 As Steema.TeeChart.TChart
    Private WithEvents CursorTool1 As New Steema.TeeChart.Tools.CursorTool
    Private Label1 As Label
    Private panels() As Panel = New Panel(15) {}
    Private stopWatch As System.Diagnostics.Stopwatch

    Private Sub InitializeChart()

        Dim w As Integer = 150
        Dim h As Integer = 100

        For i As Integer = 0 To panels.Length - 1
            panels(i) = New Panel

            MyChart = New Steema.TeeChart.TChart()

            Me.Controls.Add(panels(i))
            panels(i).Location = New Point(w * (i Mod 5), h * (i Mod 3))
            panels(i).Width = w
            panels(i).Height = h
            panels(i).Controls.Add(MyChart)

            MyChart.Dock = DockStyle.Fill

            MyChart.Series.Add(New Steema.TeeChart.Styles.FastLine())
            MyChart(0).FillSampleValues()
            MyChart(0).Color = Color.DarkBlue

            'MyChart.Legend.Visible = False
            MyChart.Header.Visible = False

            AddHandler MyChart.Zoomed, AddressOf tChart1_Zoomed
            AddHandler MyChart.UndoneZoom, AddressOf tChart1_UndoneZoom
            AddHandler MyChart.Scroll, AddressOf tChart1_Scroll
            AddHandler MyChart.ClickLegend, AddressOf tChart1_ClickLegend

            MyCursor = New Steema.TeeChart.Tools.CursorTool(MyChart.Chart)
            'MyCursor.FastCursor = True

            MyCursor.XValue = 5
            MyCursor.YValue = 5
            MyCursor.XValue = 5
        Next

        TChart1 = New Steema.TeeChart.TChart()
        Me.Controls.Add(TChart1)
        TChart1.Location = New Point(0, h * 3)

        Dim FastLine1 As New Steema.TeeChart.Styles.FastLine(TChart1.Chart)
        FastLine1.Color = Color.Red
        FastLine1.LinePen.Width = 3
        FastLine1.FillSampleValues()

        CursorTool1 = New Steema.TeeChart.Tools.CursorTool(TChart1.Chart)
        CursorTool1.Style = Steema.TeeChart.Tools.CursorToolStyles.Vertical
        CursorTool1.FollowMouse = True

        AddHandler CursorTool1.Change, AddressOf cursorTool1_Change

        Label1 = New Label
        Me.Controls.Add(Label1)
        Label1.Location = New Point(TChart1.Width + 10, TChart1.Location.Y + 100)
        Label1.AutoSize = True

        Me.Width = w * 5
        Me.Height = h * 3 + TChart1.Height

        stopWatch = New System.Diagnostics.Stopwatch()

        AddHandler CType(panels(0).Controls.Item(0), Steema.TeeChart.TChart).BeforeDraw, AddressOf MyChart_BeforeDraw
        AddHandler CType(panels(panels.Length - 1).Controls.Item(0), Steema.TeeChart.TChart).AfterDraw, AddressOf MyChart_AfterDraw
    End Sub

    Private Sub cursorTool1_Change(ByVal sender As Object, ByVal e As Steema.TeeChart.Tools.CursorChangeEventArgs)
        Dim i As Int32

        For i = 0 To panels.Length - 1
            CType(CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Tools.Item(0), Steema.TeeChart.Tools.CursorTool).XValue = e.XValue
        Next
    End Sub

    Private Sub MyChart_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D)
        stopWatch.Stop()

        Dim elapsedTime As TimeSpan = stopWatch.Elapsed
        Label1.Text = "Elapsed time: " + elapsedTime.TotalMilliseconds.ToString() + " ms"
    End Sub

    Private Sub MyChart_BeforeDraw(ByVal sender As System.Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D)
        stopWatch.Reset()
        stopWatch.Start()
    End Sub

    Private Sub tChart1_Zoomed(ByVal sender As Object, ByVal e As System.EventArgs)
        UpdateAxes(sender)
    End Sub

    Private Sub tChart1_Scroll(ByVal sender As Object, ByVal e As System.EventArgs)
        UpdateAxes(sender)
    End Sub

    Private Sub tChart1_UndoneZoom(ByVal sender As Object, ByVal e As System.EventArgs)
        UpdateAxes(sender)
    End Sub

    Private Sub UpdateAxes(ByVal sender As Object)
        Dim OrgChart As Steema.TeeChart.TChart = CType(sender, Steema.TeeChart.TChart)
        Dim DestChart As Steema.TeeChart.TChart

        OrgChart.Refresh()

        For i As Integer = 0 To panels.Length - 1
            DestChart = CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart)

            If (Not OrgChart.Equals(DestChart)) Then
                DestChart.Axes.Bottom.SetMinMax(OrgChart.Axes.Bottom.Minimum, OrgChart.Axes.Bottom.Maximum)
                DestChart.Axes.Left.SetMinMax(OrgChart.Axes.Left.Minimum, OrgChart.Axes.Left.Maximum)
            End If
        Next
    End Sub

    Private Sub tChart1_ClickLegend(ByVal sender As Object, ByVal e As MouseEventArgs)
        Dim MyChart As Steema.TeeChart.Chart = CType(sender, Steema.TeeChart.Chart)

        Dim Index As Integer = MyChart.Legend.Clicked(e.X, e.Y)
        Dim Series As Steema.TeeChart.Styles.FastLine

        If ((Index <> -1) And (MyChart.Series.Count >= Index)) Then
            Series = CType(MyChart.Series(Index), Steema.TeeChart.Styles.FastLine)
            Steema.TeeChart.Editors.PenEditor.Edit(Series.LinePen)
        End If
    End Sub

End Class
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