Print asp.net chart when TempChart is set to Session

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Sigma nBiT AB
Newbie
Newbie
Posts: 2
Joined: Fri Nov 15, 2002 12:00 am

Print asp.net chart when TempChart is set to Session

Post by Sigma nBiT AB » Mon Dec 15, 2003 9:58 am

Hi
I have an aps.net application with a chart. The TempChart property on the
chart is set to "SESSION".

The chart is created by the following code (and a file GetChart.aspx):

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ch1 As Steema.TeeChart.Chart = WebChart1.Chart
Dim tmpChart As System.IO.MemoryStream = New System.IO.MemoryStream

If Session("ch1") Is Nothing Then
series.FillSampleValues(5)
ch1.Series.Add(series)

' export Chart to a MemoryStream template
ch1.Export.Template.Save(tmpChart)

' save template to a Session variable
Session.Add("ch1", tmpChart)
Else
' retrieve the session stored Chart
tmpChart = DirectCast(Session("ch1"), System.IO.MemoryStream)

' set the Stream position to 0 as the last read/write
' will have moved the position to the end of the stream
tmpChart.Position = 0

' import saved Chart
ch1.Import.Template.Load(tmpChart)
End If

'ch1.Series(0).Marks.Style =
Steema.TeeChart.Styles.MarksStyles.Label
ch1.Series(0).Marks.Color = Color.White
End Sub


GetChart.aspx looks like:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim chartName As String = Request.QueryString("Chart")

If Not Session(chartName) Is Nothing Then
Dim chartStream As System.IO.MemoryStream = New
System.IO.MemoryStream '
chartStream = DirectCast(Session(chartName),
System.IO.MemoryStream)
Response.OutputStream.Write(chartStream.ToArray, 0,
chartStream.Length)
chartStream.Close()
Session.Remove(chartName)
End If
End Sub


The chart is generated as it should (looks good on the screen) but when
the webpage is printed, only a big red X is printed where the chart should
be located.

If the TempChart property on the chart is set to "FILE" the print
operation is working.

My question to you is therefore:
What should I do to get print to work when TempChart is set to SESSION?

I have tried to add the following code to GetChart.aspx (but it did not help):
Response.ContentType = "image/gif"

Best regards
Göran, Sigma nBiT AB Sweden

Sigma nBiT AB
Newbie
Newbie
Posts: 2
Joined: Fri Nov 15, 2002 12:00 am

Post by Sigma nBiT AB » Tue Dec 16, 2003 12:25 pm

I have found a solution to the problem described above:

Remove the following line from Load method in GetChart.aspx:

chartStream.Close()!

Print will now work as you intended!

The method will then look as:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim chartName As String = Request.QueryString("Chart")
If Not Session(chartName) Is Nothing Then

Dim chartStream As System.IO.MemoryStream = New System.IO.MemoryStream
chartStream = DirectCast(Session(chartName), System.IO.MemoryStream)

Response.ContentType = "image/png"
Response.AppendHeader("Content-Disposition", "inline; filename=prognos.png")
Response.OutputStream.Write(chartStream.ToArray, 0, chartStream.Length)
Response.End()
End If
End Sub

Best regards
Göran Arvidsson Sigma nBiT AB

Post Reply