Page 1 of 1

TeeChart3.5 in ASP. Zoom functionality

Posted: Wed Aug 12, 2009 3:00 pm
by 13052858
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);
}

Re: TeeChart3.5 in ASP. Zoom functionality

Posted: Thu Aug 13, 2009 10:31 am
by 10050769
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,

Re: TeeChart3.5 in ASP. Zoom functionality

Posted: Thu Aug 13, 2009 11:42 am
by 13052858
..

Re: TeeChart3.5 in ASP. Zoom functionality

Posted: Thu Aug 13, 2009 11:48 am
by 13052858
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 13880 times
I want the zoomed area to be the same after the page refresh. How can I do this?

Thanks in advance

Re: TeeChart3.5 in ASP. Zoom functionality

Posted: Fri Aug 14, 2009 11:17 am
by 10050769
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,

Re: TeeChart3.5 in ASP. Zoom functionality

Posted: Fri Aug 14, 2009 4:15 pm
by Marc
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

Re: TeeChart3.5 in ASP. Zoom functionality

Posted: Wed Aug 19, 2009 6:37 am
by 13052858
Thanks, now I have the zoom functionality I wanted!! and it works perfect!