Page 1 of 1

Zoom in Teechart for .Net

Posted: Mon Jul 17, 2006 10:19 pm
by 9638028
Hi,

I'm a newbie to using TeeChart, but I am having difficulty getting the zoom capability to work at all. I stepped through the Tutorial "Walkthrough ASP.Net examples" but I get stuck every time I try to implement the zoom. An exception is thrown every time in the CheckZoom function

private void CheckZoom(WebChart wChart)
{
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);
}

in particular the exception happens in the SetCurrentZoom call. I get this

System.ArgumentException was unhandled by user code
Message="Parameter is not valid."
Source="System.Drawing"
StackTrace:
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
at Steema.TeeChart.Chart.Bitmap(Int32 width, Int32 height, PixelFormat pixelformat)
at Steema.TeeChart.Chart.Bitmap(Int32 width, Int32 height)
at Steema.TeeChart.Chart.Bitmap()
at Steema.TeeChart.Tools.ZoomTool.Zoom(Rectangle r)
at Steema.TeeChart.Tools.ZoomTool.DoZoom(ArrayList zoomState)
at Steema.TeeChart.Tools.ZoomTool.SetCurrentZoom(HttpRequest r, ArrayList zoomState)
at _Default.CheckZoom(WebChart wchart) in c:\AtlasWebSite2\Default.aspx.cs:line 40
at _Default.Page_Load(Object sender, EventArgs e) in c:\AtlasWebSite2\Default.aspx.cs:line 32
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

if I try to zoom anything.

What am I missing here?

FYI: I am using VS 2005.

Regards,

Layne

Posted: Tue Jul 18, 2006 9:10 am
by narcis
Hi Layne,

The code you posted is fine, is identic to the one in the ASP.NET demo. Could you please send us ane example we can run "as-is" to reproduce the issue here?

You can post your files at news://www.steema.net/steema.public.attachments newsgroup.

Unable to get to that newsgroup

Posted: Tue Jul 18, 2006 3:22 pm
by 9638028
Hi,

I am unable to get to that newsgroup you linked to. We have proxies and are blocked from direct contact here, so my newsreader can't get in.

Is there another way to send you the files? I just redid the project again this morning, with the same results. I can reproduce this exception on whim.

A little more evidence for you. The exception only appears to throw itself if you are marking a zoom area from the upper left to the lower right.

Regards,

~layne

Posted: Tue Jul 18, 2006 6:41 pm
by 9638028
Narcis,

I tried an alternate path to upload those files. Even from home I can't upload them. When I try from there, it says the message is too big, though it is a 3 line response with an attachment of 4 files, approximately 1k each, zipped into a package. Size shouldn't be an issue.

Any ideas?

~layne

Posted: Wed Jul 19, 2006 10:49 am
by narcis
Hi Layne,

Thanks for the files, I could reproduce the problem here and modified your files so that it works fine. It needs like the code below. I'm also posting the file in the attachments newsgroup.

Code: Select all

	private void Page_Load(object sender, System.EventArgs e)
	{
		//Let's work with the Chart object for convenience
		Steema.TeeChart.Chart Chart1 = WebChart1.Chart;
    MemoryStream tmpChart = new MemoryStream();

    //Add a ZoomTool to the Chart
    Steema.TeeChart.Tools.ZoomTool zoomTool1 = new Steema.TeeChart.Tools.ZoomTool(Chart1);

    //Add a SeriesToolTip to the Chart
    Steema.TeeChart.Tools.SeriesHotspot seriesHotSpot1 = new Steema.TeeChart.Tools.SeriesHotspot(Chart1);
    //Steema.TeeChart.Styles.MapAction.Mark is the default value
    seriesHotSpot1.MapAction = Steema.TeeChart.Styles.MapAction.Mark;

    if (Session["ch1"] == null)
    {
		  //Add in a series and fill it
		  Chart1.Aspect.View3D = false;
      if (Chart1.Series.Count < 1)
      {
		    Steema.TeeChart.Styles.Bubble bubble1 = new Steema.TeeChart.Styles.Bubble(Chart1);
      }
      Chart1.Series[0].FillSampleValues();

      //export Chart to a MemoryStream template
      Chart1.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
      WebChart1.Chart.Import.Template.Load(tmpChart);

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

	}
	
	private void CheckZoom(WebChart wChart)
	{ 
		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);    
	} 

Posted: Wed Jul 19, 2006 4:49 pm
by 9638028
Hi Narcis,

This didn't work for me. I still can't access this newsgroup from within my work environment, so I can't download your edits to my files. However, I C&P'd the code you posted here into my play project. It is still throwing the same exception (Parameter is not valid) for that SetCurrentZoom call in the CheckZoom method when I try to set the zoom area from upper left to lower right.

Did you do edits to the other files as well? I'll try pulling them down this evening when I get home, but in the meanwhile, for your perusal I have C&P'd my default.aspx.cs file here for you.

Regards,

Layne

using System;
using System.Data;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Steema.TeeChart.Web;

public partial class _Default : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
//Let's work with the Chart object for convenience
Steema.TeeChart.Chart Chart1 = WebChart1.Chart;
MemoryStream tmpChart = new MemoryStream();

//Add a ZoomTool to the Chart
Steema.TeeChart.Tools.ZoomTool zoomTool1 = new Steema.TeeChart.Tools.ZoomTool( Chart1 );

//Add a SeriesToolTip to the Chart
Steema.TeeChart.Tools.SeriesHotspot seriesHotSpot1 = new Steema.TeeChart.Tools.SeriesHotspot( Chart1 );
//Steema.TeeChart.Styles.MapAction.Mark is the default value
seriesHotSpot1.MapAction = Steema.TeeChart.Styles.MapAction.Mark;

if ( Session[ "ch1" ] == null )
{
//Add in a series and fill it
Chart1.Aspect.View3D = false;
if ( Chart1.Series.Count < 1 )
{
Steema.TeeChart.Styles.Bubble bubble1 = new Steema.TeeChart.Styles.Bubble( Chart1 );
}
Chart1.Series[ 0 ].FillSampleValues();

//export Chart to a MemoryStream template
Chart1.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
WebChart1.Chart.Import.Template.Load( tmpChart );

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

}

private void CheckZoom( WebChart wChart )
{
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 );
}
}

Posted: Thu Jul 20, 2006 7:46 am
by narcis
Hi Layne,

No, I just edited Default.aspx.cs as I wrote here. Which TeeChart for .NET v2 built are you using?

Thanks in advance.

Posted: Thu Jul 20, 2006 4:38 pm
by 9638028
Hi,

According to the about Steema.Teechart..., I am on version 2.0.2306.26232

~layne

Posted: Thu Jul 20, 2006 4:46 pm
by 9638028
Narcis,

I just tried your code from the attachments newsgroup and it zoomed for me. For the life of me though, I don't know why yours would work and mine wouldn't, since mine was just a copy and paste of what you had here.

Thanks...though, I daresay I will be contacting you again. :(

~layne

Posted: Thu Jul 20, 2006 5:40 pm
by 9638028
Ok, one more piece of evidence...

For some reason, the size of the control seems important. I noticed in your default.aspx file that you set the size of the control to 300px X 400px, which mine was lacking (I hadn't set sizes at all). When I set the size, it started working.

No knowing why...

~layne