How to cache a graph in a Web Form

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Sophie
Newbie
Newbie
Posts: 5
Joined: Fri Nov 15, 2002 12:00 am
Location: Canada
Contact:

How to cache a graph in a Web Form

Post by Sophie » Wed Feb 01, 2006 4:46 pm

Hi,
When a Web Form page is postback, I don't want to generate the graph again. How I can store and retrieve my graph from the cache?

I tried to retrieve the session variable created by TempChart=Session, but the name of session variable change every time the page is post back.

Thanks for help me,
Sophie Morissette

Sophie
Newbie
Newbie
Posts: 5
Joined: Fri Nov 15, 2002 12:00 am
Location: Canada
Contact:

Post by Sophie » Wed Feb 01, 2006 7:55 pm

I found the solution in the example ClickElementsChart.aspx

Code: Select all

			// ****************************************************
			//The data load code for WebChart1 demostrates a technique to save 
			//data between page calls. The Chart is saved as a TeeChart template 
			//to a session variable.
			// ****************************************************
			Steema.TeeChart.Chart ch1=WebChart1.Chart;
			MemoryStream tmpChart=new MemoryStream();

			if (Session["ch3"]==null)
			{			
				//setup Chart
				if (ch1.Series.Count<2)
				{ 
					ch1.Series.Add(new Steema.TeeChart.Styles.Points());
					ch1.Series.Add(new Steema.TeeChart.Styles.Points());
				}				

				((Points)ch1.Series[0]).Pointer.Pen.Visible=false;
				((Points)ch1.Series[1]).Pointer.Pen.Color=Color.FromArgb(79,79,255);
		
				ch1.Series[0].Color=Color.FromArgb(255,199,26);
				ch1.Series[1].Color=Color.FromArgb(106,106,255);

				ch1.Series[0].FillSampleValues(6);
				ch1.Series[1].FillSampleValues(6);
				//export Chart to a MemoryStream template
				ch1.Export.Template.Save(tmpChart);
				//save template to a Session variable
				Session.Add("ch3",tmpChart);
			}
			else
			{
				//retrieve the session stored Chart
				tmpChart=(MemoryStream)Session["ch3"];
				//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);
			}
Sophie :wink:

Post Reply