Page 1 of 1

Charts with data table tool in web application

Posted: Sat Jul 02, 2011 4:39 am
by 15654268
Hi there,
I'm using dotnet version 4.1.2010.9280 and am having a problem displaying charts in a web application where the chart includes a data table tool. Here is the situation.

I have a windows form application that allows users to create charts and which stores the .ten file in a database, I recently included functionality that allows a data tabel tool to be included on the charts if required.

I also have a web application that used tchart web component to display the .ten files previously saved in the database. Up until I added functionality to allow data tables on that charts this has all worked fine, however, now I'm having problems. See the following code, to get this to work I have to remove the data table tool with the marked code otherwise the foillowing line throws this error.
"Unable to cast object of type 'Steema.TeeChart.Web.WebChart' to type 'Steema.TeeChart.TChart'
The Refresh_Source function takes two parameters the first being of type STEEMA.TCHART.CHART. It is this that it is complaining about and ONLY complains if there is a data table present on the chart.

Code: Select all

 Dim memstream As New System.IO.MemoryStream(m_chart.m_bTeeData)
            memstream.Position = 0
            WebChart.Clear()

            WebChart.Chart.Import.Template.Load(memstream)

>>>>> 
if this bit is removed the following line fails.
            For i As Integer = WebChart.Chart.Tools.Count - 1 To 0 Step -1
               WebChart.Chart.Tools.RemoveAt(i)
            Next
>>>>> 

            m_chart.Refresh_Source(WebChart.Chart, m_sByValue)

Re: Charts with data table tool in web application

Posted: Mon Jul 04, 2011 8:47 am
by 10050769
Hello Adrian,

I have made a simple project following your steps and last version of TeeChart.Net 2011 and seems it works fine for me:

Code: Select all

Protected Sub Page_Load(sender As Object, e As EventArgs)
	InitializeChart()
End Sub
Private Series1 As Steema.TeeChart.Styles.Line
Private tmpChart As System.IO.MemoryStream
Private tool3 As Steema.TeeChart.Tools.DataTableTool

Protected Sub InitializeChart()
	Dim ch1 As Steema.TeeChart.Chart
	tmpChart = New System.IO.MemoryStream()
	If Session("ch1") Is Nothing Then
		ch1 = WebChart1.Chart
		ch1.Aspect.View3D = False
		Series1 = New Steema.TeeChart.Styles.Line(ch1)
		Series1.FillSampleValues()

		tool3 = New Steema.TeeChart.Tools.DataTableTool(WebChart1.Chart)

		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
		WebChart1.Chart.Import.Template.Load(tmpChart)
		For i As Integer = WebChart1.Chart.Tools.Count - 1 To 0 Step -1

			WebChart1.Chart.Tools.RemoveAt(i)
		Next

		WebChart1.Chart.Invalidate()
	End If
End Sub
Please can you tell us if previous code reproduce your problem? If previous code doesn't reproduce your problem, please try to arrange a simple code so we can reproduce exactly your problem here.

Thanks,

Re: Charts with data table tool in web application

Posted: Mon Jul 04, 2011 12:48 pm
by 15654268
Hi Sandra,
Try your sample without the following

Code: Select all

For i As Integer = WebChart1.Chart.Tools.Count - 1 To 0 Step -1
         WebChart1.Chart.Tools.RemoveAt(i)
Next
I added that to remove the data table because with the data table there it would fail to cast correctly on my next line of code.

Re: Charts with data table tool in web application

Posted: Mon Jul 04, 2011 2:39 pm
by 10050769
Hello Adrian,

Sorry but I'm not able to reproduce the problem here with the modifications you suggested and the same TeeChart build as you use. Can you please attach a simple example project we can run "as-is" to reproduce the problem here and check that it's using the TeeChart version you mentioned?

Thanks,