NET 2.0 WebChart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Pratty
Newbie
Newbie
Posts: 22
Joined: Wed Jan 24, 2007 12:00 am

NET 2.0 WebChart

Post by Pratty » Tue Apr 17, 2007 2:00 am

Hi,

I've trying to find a way to enforce a fixed minimum y axis value independent of user zoom on a web chart.

I have a chart displaying values that always have a minimum of 0.0. I want to lock the y axis minimum so that even if the user selects a zoom rectangle that extends below 0.0 on the y axis, the resulting view is bounded by 0.0.

Any ideas how I can achieve this?

Thanks,
Andrew

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Apr 17, 2007 3:52 pm

Hi Andrew,

Yes, this is a little bit complicated but can be achieved doing something like this:

Code: Select all

	protected void Page_Load(object sender, EventArgs e)
	{
		Steema.TeeChart.Chart ch1 = WebChart1.Chart;
		MemoryStream tmpChart = new MemoryStream();

		if (Session["ch1"] == null)
		{
			//setup Chart
			if (ch1.Series.Count < 2)
			{
				ch1.Series.Add(new Steema.TeeChart.Styles.Points());
				ch1.Series.Add(new Steema.TeeChart.Styles.Points());
			}
			//((Steema.TeeChart.Tools.ZoomTool)ch1.Tools[0]).ZoomPenColor=Color.Yellow;

			((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(36);
			ch1.Series[1].FillSampleValues(36);
			//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 = (MemoryStream)Session["ch1"];
			//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);

			HttpRequest myReq = new HttpRequest(Request.FilePath,Request.Url.ToString(),getZoomArgs(Request));

			//check whether zoom request is being sent
			CheckZoom(WebChart1,myReq);
		}
	}

	protected string getZoomArgs(HttpRequest r)
	{
		Steema.TeeChart.Chart ch1 = WebChart1.Chart;
		string tmpStr = "";
		Hashtable argumentList = new Hashtable();
		if ((r.Params["__EVENTARGUMENT"] != null) && (r.Params["__EVENTARGUMENT"].Length > 0))
		{
			char[] pairs = new char[1] { ';' };
			char[] vals = new char[1] { '$' };

			String[] varpairs = r.Params["__EVENTARGUMENT"].Split(pairs);

			Bitmap bmp = ch1.Bitmap();
			foreach (string s in varpairs)
			{					
				if (s.Split(vals)[0] == "x0") 
					tmpStr = tmpStr + "x0="+ ch1.Axes.Bottom.CalcXPosValue(0) + "&";
				else 
					if (s.Split(vals)[0] == "y1")
						tmpStr = tmpStr + "y1=" + ch1.Axes.Left.CalcYPosValue(0) + "&";
					else
						tmpStr = tmpStr + s.Split(vals)[0] + "=" + s.Split(vals)[1] + "&";
				
			}
			
		}
		return tmpStr;
	}

	private void CheckZoom(WebChart wChart, HttpRequest request)
	{
		ArrayList zoomedState = (ArrayList)Session[wChart.ID + "Zoomed"];
		zoomedState = ((Steema.TeeChart.Tools.ZoomTool)wChart.Chart.Tools[0]).SetCurrentZoom(request,
			zoomedState);
		if (zoomedState == null)
			Session.Remove(wChart.ID + "Zoomed");
		else
			Session.Add(wChart.ID + "Zoomed", zoomedState);
	}
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 » Tue Apr 17, 2007 4:03 pm

Hi Andrew,

As a follow up to my previous message, an enhancement could be implementing getZoomArgs like this:

Code: Select all

	protected string getZoomArgs(HttpRequest r)
	{
		Steema.TeeChart.Chart ch1 = WebChart1.Chart;
		string tmpStr = "";
		Hashtable argumentList = new Hashtable();
		if ((r.Params["__EVENTARGUMENT"] != null) && (r.Params["__EVENTARGUMENT"].Length > 0))
		{
			char[] pairs = new char[1] { ';' };
			char[] vals = new char[1] { '$' };

			String[] varpairs = r.Params["__EVENTARGUMENT"].Split(pairs);

			Bitmap bmp = ch1.Bitmap();
			foreach (string s in varpairs)
			{
				if ((s.Split(vals)[0] == "x0") && ( ch1.Axes.Bottom.IStartPos < ch1.Axes.Bottom.CalcXPosValue(0) ))
					tmpStr = tmpStr + "x0=" + ch1.Axes.Bottom.CalcXPosValue(0) + "&";
				else
					if ((s.Split(vals)[0] == "y1") && ( ch1.Axes.Left.IEndPos < ch1.Axes.Left.CalcYPosValue(0) ))
						tmpStr = tmpStr + "y1=" + ch1.Axes.Left.CalcYPosValue(0) + "&";
					else
						tmpStr = tmpStr + s.Split(vals)[0] + "=" + s.Split(vals)[1] + "&";
				
			}
			
		}
		return tmpStr;
	}
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

Post Reply