TeeChart3.5 in ASP. Zoom functionality

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
marcoIpcos
Newbie
Newbie
Posts: 11
Joined: Mon Mar 23, 2009 12:00 am

TeeChart3.5 in ASP. Zoom functionality

Post by marcoIpcos » Wed Aug 12, 2009 3:00 pm

The help describes the function
SetCurrentZoom(System.Web.HttpRequest, System.Collections.ArrayList, System.Collections.Specialized.NameValueCollection) to use if there are post elements (eg. Button or DropDownList) on the page that might send a non-zoom page request. This function is not working in my application (using exactly the code as described in the help of this function). It simply does not zoom at all.
Using another overload of this function (public ArrayList SetCurrentZoom(HttpRequest r, ArrayList zoomState)) really is zooming in and out, but at every page refresh it performs the same zoom action to the current shown chart as it has done at the last zoom action. this causes to zoom in more and more at each page refresh.

How can I provide proper zoom functionality if there are more elements that can cause page-refresh requests?

The code I use(Zoom example in A Walk-through ASP.NET examples) :
private void Page_Load(object sender, System.EventArgs e)
{
MemoryStream tmpChart;

if (Session["ch1"] == null)
{
WebChart1.Chart[0].FillSampleValues();
WebChart1.Chart.Tools.Add(new Steema.TeeChart.Tools.ZoomTool(WebChart1.Chart));
tmpChart = new MemoryStream();
WebChart1.Chart.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);
CheckZoom(WebChart1);
}
}

private void CheckZoom(WebChart wChart)
{
ArrayList zoomedState = (ArrayList)Session[wChart.ClientID + "Zoomed"];
zoomedState = ((Steema.TeeChart.Tools.ZoomTool)wChart.Chart.Tools[0]).SetCurrentZoom(Request,zoomedState, DeterminePostBackMode());
if (zoomedState == null)
Session.Remove(wChart.ClientID + "Zoomed");
else
Session.Add(wChart.ClientID + "Zoomed", zoomedState);
}

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: TeeChart3.5 in ASP. Zoom functionality

Post by Sandra » Thu Aug 13, 2009 10:31 am

Hello marcoIpcos,

Please add WebChart1.AutoPostBack = true in your Page_Load specifically after if(Session["ch1]==null) , and remove DeterminePostBackMode() to SetCurrentZoom() function, see next code changes:

Code: Select all

Private void Page_Load(object sender, System.EventArgs e)
    {
        System.IO.MemoryStream tmpChart;
        Steema.TeeChart.Chart ch1 = WebChart1.Chart;
        WebChart1.AutoPostback = true;//Add AutoPostback.
        if (Session["ch1"] == null)
        {
            ch1.Series.Add(new Steema.TeeChart.Styles.Line());
            ch1.Tools.Add(new Steema.TeeChart.Tools.ZoomTool());
            ch1[0].FillSampleValues();
        
            tmpChart = new System.IO.MemoryStream();
            WebChart1.Chart.Export.Template.Save(tmpChart);
            //save template to a Session variable
            Session.Add("ch1", tmpChart);
        }
        else
        {
            //retrieve the session stored Chart
            tmpChart = (System.IO.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);
            CheckZoom(WebChart1);
        }
    }

    private void CheckZoom(Steema.TeeChart.Web.WebChart wChart)
    {
        System.Collections.ArrayList zoomedState = (System.Collections.ArrayList)Session[wChart.ClientID + "Zoomed"];
        zoomedState = ((Steema.TeeChart.Tools.ZoomTool)wChart.Chart.Tools[0]).SetCurrentZoom(Request, zoomedState);//remove DeterminePostBackMode()
        if (zoomedState == null)
            Session.Remove(wChart.ClientID + "Zoomed");
        else
            Session.Add(wChart.ClientID + "Zoomed", zoomedState);
    }
Check that next code works fine in your application.

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / 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

marcoIpcos
Newbie
Newbie
Posts: 11
Joined: Mon Mar 23, 2009 12:00 am

Re: TeeChart3.5 in ASP. Zoom functionality

Post by marcoIpcos » Thu Aug 13, 2009 11:42 am

..
Last edited by marcoIpcos on Thu Aug 13, 2009 11:52 am, edited 2 times in total.

marcoIpcos
Newbie
Newbie
Posts: 11
Joined: Mon Mar 23, 2009 12:00 am

Re: TeeChart3.5 in ASP. Zoom functionality

Post by marcoIpcos » Thu Aug 13, 2009 11:48 am

Sandra wrote:Hello marcoIpcos,

Please add WebChart1.AutoPostBack = true in your Page_Load specifically after if(Session["ch1]==null) , and remove DeterminePostBackMode() to SetCurrentZoom() function, see next code changes:

Code: Select all

Private void Page_Load(object sender, System.EventArgs e)
    {
        System.IO.MemoryStream tmpChart;
        Steema.TeeChart.Chart ch1 = WebChart1.Chart;
        WebChart1.AutoPostback = true;//Add AutoPostback.
        if (Session["ch1"] == null)
        {
            ch1.Series.Add(new Steema.TeeChart.Styles.Line());
            ch1.Tools.Add(new Steema.TeeChart.Tools.ZoomTool());
            ch1[0].FillSampleValues();
        
            tmpChart = new System.IO.MemoryStream();
            WebChart1.Chart.Export.Template.Save(tmpChart);
            //save template to a Session variable
            Session.Add("ch1", tmpChart);
        }
        else
        {
            //retrieve the session stored Chart
            tmpChart = (System.IO.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);
            CheckZoom(WebChart1);
        }
    }

    private void CheckZoom(Steema.TeeChart.Web.WebChart wChart)
    {
        System.Collections.ArrayList zoomedState = (System.Collections.ArrayList)Session[wChart.ClientID + "Zoomed"];
        zoomedState = ((Steema.TeeChart.Tools.ZoomTool)wChart.Chart.Tools[0]).SetCurrentZoom(Request, zoomedState);//remove DeterminePostBackMode()
        if (zoomedState == null)
            Session.Remove(wChart.ClientID + "Zoomed");
        else
            Session.Add(wChart.ClientID + "Zoomed", zoomedState);
    }
Check that next code works fine in your application.

I hope will helps.

Thanks,
Thanks Sandra,

I also tried to use the SetCurrentZoom overload you used in your reply. The chart is zooming, but one problem still occurs:
* If I zoomed in in the chart displayed in the Web browser, and I refresh the page, the zoom action is performed again on the already zoomed graph!!
This causes the graph to be zoomed in further on every page (graph) update.
The actions I do:
* Load the page
* Manual zoom in an area with the mouse
* update the page (F5) to retrieve new data (xAxis and Yaxis are now zoomed in further!!)
Here some screenshots:
screenshots.PNG
Screenshots
screenshots.PNG (149.97 KiB) Viewed 13881 times
I want the zoomed area to be the same after the page refresh. How can I do this?

Thanks in advance

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: TeeChart3.5 in ASP. Zoom functionality

Post by Sandra » Fri Aug 14, 2009 11:17 am

Hello marcoIpcos,

TeeChart's WebChart is connectionless to the server so all information describing the zoom is carried with the current page as a session variable. The problem as you have found is that a page refresh resends the zoom request incrementing that zoom on the current zoom whose information is stored with the page.

An option would be to remove the memory of the current zoom when refreshing, that is a very workable option if you are satisfied that one depth level of zoom for your application users is enough (as all zooms will act upon the unzoomed 'stock' Chart).

To see that work make the following change to the CheckZoom method:

Code: Select all

private void CheckZoom(WebChart wChart)
{
  //ArrayList zoomedState=(ArrayList)Session[wChart.ID+"Zoomed"];
  ArrayList zoomedState = null; 

.....
I hope will helps,

Thanks,
Best Regards,
Sandra Pazos / 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

Marc
Site Admin
Site Admin
Posts: 1266
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: TeeChart3.5 in ASP. Zoom functionality

Post by Marc » Fri Aug 14, 2009 4:15 pm

Hello,

The following code in place of the current CheckZoom method should resolve the problem. You may find a way to economise on this code if you take a closer look through it.

Code: Select all

private void CheckZoom(WebChart wChart)
{
  ArrayList zoomCoords = (ArrayList)Session[wChart.ID + "zoomCoords"];
  ArrayList currentZoomCoords = new ArrayList();

  Hashtable args = getZoomArgs(Request);

  currentZoomCoords.Add(args["x0"]);
  currentZoomCoords.Add(args["x1"]);
  currentZoomCoords.Add(args["y0"]);
  currentZoomCoords.Add(args["y1"]);

  ArrayList zoomedState = null;
  ArrayList oldZoomedState = (ArrayList)Session[wChart.ID + "oldZoomed"];

  if ((currentZoomCoords != null) && (zoomCoords != null))
  {
    if (
        (zoomCoords[0].Equals(currentZoomCoords[0])) && 
        (zoomCoords[1].Equals(currentZoomCoords[1])) &&
        (zoomCoords[2].Equals(currentZoomCoords[2])) &&
        (zoomCoords[3].Equals(currentZoomCoords[3]))
       )
      if (oldZoomedState!=null)
        zoomedState = oldZoomedState;
      else
        zoomedState = null;
    else
      zoomedState = (ArrayList)Session[wChart.ID + "Zoomed"];
  }
  else
    zoomedState = (ArrayList)Session[wChart.ID + "Zoomed"];

  Session.Add(wChart.ID + "oldZoomed", zoomedState);
  if (currentZoomCoords[0]!=null)
    Session.Add(wChart.ID + "zoomCoords", currentZoomCoords);
  else
    Session.Remove(wChart.ID + "zoomCoords");

  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);
}

protected Hashtable getZoomArgs(HttpRequest r)
{
  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);

    foreach (string s in varpairs)
      if (s.IndexOf("$") != -1)
        argumentList.Add(s.Split(vals)[0], s.Split(vals)[1]);
  }

  return argumentList;
}
Regards,
Marc Meumann
Steema Support

marcoIpcos
Newbie
Newbie
Posts: 11
Joined: Mon Mar 23, 2009 12:00 am

Re: TeeChart3.5 in ASP. Zoom functionality

Post by marcoIpcos » Wed Aug 19, 2009 6:37 am

Thanks, now I have the zoom functionality I wanted!! and it works perfect!

Post Reply