AsifKhan Posted August 20, 2007 Report Share Posted August 20, 2007 I have built a small windows application where I have two charts binded to different datatables. I have a command button on the form which issues a print command. everything runs very well as long as the charts are printed once. however, i need to be able to run a loop which will bind the same charts to different datatables (having same schema only different data in them) and print the graphs. In doing so, my application stops responding. the reason why i suspect this has something to do with print command is because i commented the print command and ran my code which ran smoothly and i could see the charts refreshing correctly for each binding command. I am deallocating the system resources after each iteration and also issuing a sleep command which pauses the application for 5 secs before binding the chart to next datasource. Please let me know if there is any alternative/more suitable approcah which would solve my problem and allow my application to run the loop without crashing. Your help will be very much appreciated! Quote Link to comment Share on other sites More sharing options...
AsifKhan Posted August 20, 2007 Author Report Share Posted August 20, 2007 Another point: the application stops responding at random iterations. sometimes it could run upto 10th iteration whereas in some cases it crashes in the very beginning. In any case, I have so far not been able to run the entire loop without crashing. (the loop can go upto 200 iterations in this case, with each datasource containing upto 3000 records) Quote Link to comment Share on other sites More sharing options...
AsifKhan Posted August 20, 2007 Author Report Share Posted August 20, 2007 THE CODE:- -------- FOR FIRST CHART -------------- Private Sub bindcharts(ByRef dt1 As DataTable) TryChart1.BringToFront() Dim title1 As New ChartFX.WinForms.TitleDockable title1.Text = titletxttitle1.Font = New System.Drawing.Font("Arial", 14.0!) Chart1.Titles.Clear() Chart1.Titles.Add(title1) Chart1.DataSource = dt1 If cmb2.SelectedItem.ToString = "S1" ThenChart1.Printer.Document.DefaultPageSettings.Landscape = TrueChart1.Printer.PrintDialog() Else Chart1.Printer.Document.DefaultPageSettings.Landscape = True Chart1.Printer.Print() End If Chart1.DataSource = Nothingdt1.Dispose() Catch ex As Exception MsgBox(ex.ToString) End Try --------- FOR SECOND CHART --------------------- Try Chart2.BringToFront() Dim strsql As String = ""Dim dt As New DataTable Dim pltbarheight As Integer = 0 If rb2.Checked = True Thendt = clsDBAccess.getResultDataTable( "MY QUERY GOES HERE WHICH HAS NO ISSUES") Elsedt = clsDBAccess.getResultDataTable("QUERY") End IfDim dt7 As New DataTable Dim drnew As DataRowdt7 = clsDBAccess.getResultDataTable("QUERY") Dim dr As DataRowDim dtlayers As New DataTable Dim dc As DataColumndc = New DataColumn("Date", GetType(Date)) dtlayers.Columns.Add(dc) For Each dr In dt7.Rowsdc = New DataColumn(dr(0), GetType(Integer)) dtlayers.Columns.Add(dc) Next ' dc = New DataColumn("PLT Survey", GetType(Integer)) ' dtlayers.Columns.Add(dc)Dim recdate As DateTime recdate = DateAdd(DateInterval.Day, -1, dt.Rows(0)(1)) For Each dr In dt.Rows If dr(1) > recdate Thendrnew = dtlayers.NewRow drnew(0) = dr(1)drnew.Item(dr("layer")) = dr("pval") dtlayers.Rows.Add(drnew) recdate = dr(1) Elsedtlayers.Rows(dtlayers.Rows.Count - 1)(dr("layer")) = dr("pval") End If NextDim dtPLT As New DataTabledtPLT = clsDBAccess.getResultDataTable("QUERY") dtlayers.Merge(dtPLT) Dim dv1 As New DataView(dtlayers)dv1.Sort = " Date ASC"Chart2.DataSource = dv1.Table Dim title1 As New ChartFX.WinForms.TitleDockable title1.Text = titletxttitle1.Font = New System.Drawing.Font("Arial", 14.0!) Chart2.Titles.Clear() Chart2.Titles.Add(title1) Chart2.Printer.Document.DefaultPageSettings.Landscape = TrueChart2.Printer.Print() Chart2.DataSource = Nothingdt.Dispose() dt7.Dispose() dtlayers.Dispose() Catch ex As Exception MsgBox(ex.ToString) End Try '-------------------------- THE PIECE OF CODE WHERE I AM CALLING THE ABOVE SUBROUTINES If dt.Rows.Count > 0 Thenbindcharts(dt) Thread.Sleep(5000) bindlayermeterage(wellid) Thread.Sleep(5000) End If Quote Link to comment Share on other sites More sharing options...
AsifKhan Posted August 20, 2007 Author Report Share Posted August 20, 2007 Also, I'd like to form a single document and send it to printer rather than issuing print command for each chart. is there any way i could achieve that? Quote Link to comment Share on other sites More sharing options...
Frank Posted August 20, 2007 Report Share Posted August 20, 2007 If you want to create your own print job you can but instead of using Chart.Print use Chart.Paint to draw the chat into the printer's graphics. You can draw as many charts as you want and you will have control over the layout. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.