Dynamically generating the charts

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
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 Jan 07, 2009 11:10 am

Hi asupriya,
Please answer this question as it holds key to the solution to many of my problems.
Ok, I have posted a reply here.
Please also suggest solution to multi-chart printing and chart x-axis values alignment issues
I also posted an alignment reply here.

We will get back to you regarding the printing issue.
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

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 Jan 07, 2009 3:17 pm

Hi asupriya,
We will get back to you regarding the printing issue.
This works fine using this code:

Code: Select all

    Private WithEvents button1 As Button

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Width = 800
        Me.Height = 600

        InitializeChart()

        button1 = New Button()
        Me.Controls.Add(button1)
        button1.Location = New Point(Me.Width / 2, Me.Height - button1.Height * 3)
        button1.Text = "Print"
        button1.AutoSize = True
        AddHandler button1.Click, AddressOf button1_Click
    End Sub

    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim tChart As Steema.TeeChart.TChart = CType(Controls(0), Steema.TeeChart.TChart)

        tChart.Printer.BeginPrint()
        Dim i As Integer
        For i = 1 To 4
            tChart.Printer.Print(CType(Controls(i), Steema.TeeChart.TChart).Chart, rects(i))
        Next
        tChart.Printer.Print(rects(0))
        tChart.Printer.EndPrint()
    End Sub

    Dim rects() As Rectangle

    Private Sub InitializeChart()
        rects = New Rectangle(5) {}
        Dim rect As Rectangle

        Dim i As Integer
        For i = 0 To 4
            Dim tChart1 As Steema.TeeChart.TChart = New Steema.TeeChart.TChart()
            Me.Controls.Add(tChart1)
            rect = New Rectangle(New Point(0, 100 * i), New Size(Me.Width, 100))
            rects(i) = rect
            tChart1.Location = rect.Location
            tChart1.Width = rect.Width
            tChart1.Height = rect.Height

            Dim fastLine1 As Steema.TeeChart.Styles.FastLine = New Steema.TeeChart.Styles.FastLine(tChart1.Chart)
            fastLine1.FillSampleValues()
        Next
    End Sub
In your project, implementing PrintToolStripMenuItem_Click like this:

Code: Select all

    Private Sub PrintToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
        Dim i As Int32
        'PageSettings()
        OrgChart1 = CType(panels(0).Controls.Item(0), Steema.TeeChart.TChart)
        OrgChart1.Printer.BeginPrint()
        For i = 1 To 4 'panels.Length - 1
            Try
                OrgChart1.Printer.Print(CType(panels(i).Controls.Item(0), Steema.TeeChart.TChart).Chart, New Rectangle(100, (i * 200), 300, 200))
            Catch ex As Exception
            End Try
        Next

        OrgChart1.Printer.Print(New Rectangle(100, (i * 200), 300, 200))
        OrgChart1.Printer.EndPrint()

        'myDocument1.PrintController = New System.Drawing.Printing.StandardPrintController()

        'myDocument1.DefaultPageSettings.Landscape = True
        'myDocument1.DefaultPageSettings.Margins.Left = 100
        'myDocument1.DefaultPageSettings.Margins.Top = 100
        'myDocument1.Print()

        'OrgChart1.Printer.Print(New Rectangle(100, (i * 200) + 10, 300, 200))
        'OrgChart.Printer.Print()  ' This call only prints the origChart and nothing else. Where as the call to printpreview shows all charts - why?
        'OrgChart1.Printer.Preview() ' Only one page is supported? How to get charts to "spill over" to additional pages?
    End Sub
Also works fine. Is this what you expect?

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

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

Post by asupriya » Thu Jan 08, 2009 6:35 am

Thanks for the suggestion. However, it is not what i wanted.

I got it today working by some tweaking with the document_PrintPagefunction and manipulating some metafile drawing with System.Drawing.Printing.PrintPageEventArgs.

Essentially, the solution is to define two (or more) meta files for charts on a single page and draw them sequentially on the same page before progressing to the next.

Post Reply