Page 1 of 1
post zoom axes values should not go out of bounds
Posted: Thu Dec 09, 2010 4:15 am
by 15657590
Hi
I am using TeeChart for ASP .NET.
In the current behavior, when a part of the rectangle that the user selects to zoom is outside the axes (eg: left of left axis, below bottom axis, above top axis or right of right axis), the zoomed chart displays values that were not part of the original chart.
Eg. If the un-zoomed image has the bottom axis starting at the zero. If the user starts his zoom rectangle from left of the left axis. Then the zoomed image has bottom axis values starting from less than zero.
Is there a way to stop the axes values from going out of bounds, even though the user's rectangle started from outside the chart area.
thanks
Jag
Re: post zoom axes values should not go out of bounds
Posted: Thu Dec 09, 2010 4:52 pm
by 10050769
Hello Jag,
I recommend you take a look in TeeChart Asp.Net Demo that you find
here, concretely in
interacting with Charts \Zooming on WebForm. If it doesn't help you to solve your problem, please send us a simple project or explain exactly what you want to get. Because, we can try to help you solve your problem.
I hope will helps.
Thanks,
Re: post zoom axes values should not go out of bounds
Posted: Thu Dec 09, 2010 5:19 pm
by 15657590
The behavior I had mentioned can be reproduced in the tutorial that you suggested.
Here is how I select my rectangle. (see lower left corner)
[img]
http://i.imgur.com/cCpOl.png
[/img]
Here is how it zooms.
[img]
http://i.imgur.com/EYoDT.png
[/img]
We can see that the x-axis starts from -4 in the zoomed chart. But in the original chart the x-axis had no negative values.
The above may very well be the behavior that developers had intended. But what I am asking for is... Is there a way to prevent zoomed chart from displaying axes values that were not in the original chart.
OR can the selected rectangle be cropped to ignore area outside of the chart area?
thanks
Jag
Re: post zoom axes values should not go out of bounds
Posted: Fri Dec 10, 2010 5:34 am
by 15657590
Hmmm.. If above is still not clear.. let me explain more...
For eg:
1. User is trying to zoom into top left corner of the graph.
2. He selects a rectangle from (10,10)-top left to (100, 100)-bottom right. (in pixels)
3. But the t1.chart.left.Istartpos = 50 and t1.chart.bottom.Istartpos = 50.
4. Now the zoomed chart instead of displaying from (10,10) to (100, 100), should instead display from (50, 50) to (100, 100).
5. The rectangle that the user selects should be cropped according to the Istartpos and Iendpos of the axes.
thanks
Jag
Re: post zoom axes values should not go out of bounds
Posted: Fri Dec 10, 2010 2:38 pm
by 10050769
Hello Jag,
I have made a simple code for your. Please check if next code works as you want:
Code: Select all
public partial class _Page1 : System.Web.UI.Page
{
Steema.TeeChart.Styles.Points points1, points2;
Steema.TeeChart.Tools.ZoomTool tool1;
System.IO.MemoryStream tmpChart;
protected void Page_Load(object sender, System.EventArgs e)
{
Steema.TeeChart.Chart ch1 = WebChart1.Chart;
tmpChart = new System.IO.MemoryStream();
if (Session["ch1"] == null)
{
ch1.AutoRepaint = false;
ch1.Aspect.View3D = false;
tool1 = new Steema.TeeChart.Tools.ZoomTool(WebChart1.Chart);
tool1.ZoomPenColor = System.Drawing.Color.OliveDrab;
ch1.Panel.Gradient.Visible = false;
ch1.Walls.Visible = false;
points1 = new Steema.TeeChart.Styles.Points(ch1);
points2 = new Steema.TeeChart.Styles.Points(ch1);
points1.FillSampleValues();
points2.FillSampleValues();
ch1.Export.Template.Save(tmpChart);
//save template to a Session variable
Session.Add("ch1", tmpChart);
WebChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(WebChart1_AfterDraw);
}
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);
WebChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(WebChart1_AfterDraw);
}
}
void WebChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
double Min, Max;
Min = Math.Min(WebChart1.Chart[0].XValues.Minimum, WebChart1.Chart[1].XValues.Minimum);
Max = Math.Max(WebChart1.Chart[0].XValues.Maximum, WebChart1.Chart[1].XValues.Maximum);
WebChart1.Chart.Axes.Bottom.SetMinMax(Min, Max);
}
private void CheckZoom(Steema.TeeChart.Web.WebChart wChart)
{
System.Collections.ArrayList zoomedState = (System.Collections.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);
}
}
I hope will helps.
Thanks,
Re: post zoom axes values should not go out of bounds
Posted: Fri Dec 10, 2010 6:17 pm
by 15657590
Your code just stop the bottom axis from zooming at all. I am sorry but this is not what I need.
What I need is something like below:
The way the zoom now works is (pl correct me if I am wrong)
1. Httprequest variable gives me two pairs of (x,y) values one for top left corner(x0, y0) and another for bottom right corner(x1, y1).
2. With the help of the two (x,y) values the setCurrentZoom function zooms.
I would like to do something like below after step (1) before I send it to step (2) setCurrentZoom function,
if (x0 < Bottom.IStartPos)
x0 = Bottom.IStartPos;
if (y0 < Left.IStartPos)
y0 = Left.IStartPos;
if (x1 > Bottom.IEndPos)
x1 = Bottom.IEndPos;
if (y1 > Left.IEndPos)
y1 = Left.IEndPos;
But I am somehow not able to do this properly.
Please tell me if the explanation is unclear.
thanks
Jag
Re: post zoom axes values should not go out of bounds
Posted: Mon Dec 13, 2010 12:03 pm
by 10050769
Hello Jag,
Ok. I have made other example where is saving in a Session variable Min and Max Values. Please, check if next code works as you want:
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Page1 : System.Web.UI.Page
{
Steema.TeeChart.Styles.Points points1, points2;
Steema.TeeChart.Tools.ZoomTool tool1;
System.IO.MemoryStream tmpChart;
Double Min, Max;
protected void Page_Load(object sender, System.EventArgs e)
{
Steema.TeeChart.Chart ch1 = WebChart1.Chart;
tmpChart = new System.IO.MemoryStream();
if (Session["ch1"] == null)
{
ch1.AutoRepaint = false;
ch1.Aspect.View3D = false;
tool1 = new Steema.TeeChart.Tools.ZoomTool(WebChart1.Chart);
tool1.ZoomPenColor = System.Drawing.Color.OliveDrab;
ch1.Panel.Gradient.Visible = false;
ch1.Walls.Visible = false;
points1 = new Steema.TeeChart.Styles.Points(ch1);
points2 = new Steema.TeeChart.Styles.Points(ch1);
points1.FillSampleValues();
points2.FillSampleValues();
ch1.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);
System.Drawing.Bitmap bmp = WebChart1.Chart.Bitmap((int)WebChart1.Width.Value, (int)WebChart1.Height.Value);
Min = WebChart1.Chart.Axes.Bottom.Minimum;
Max = WebChart1.Chart.Axes.Bottom.Maximum;
CheckZoom(WebChart1);
}
}
private void CheckZoom(Steema.TeeChart.Web.WebChart wChart)
{
System.Collections.ArrayList zoomedState = (System.Collections.ArrayList)Session[wChart.ID + "Zoomed"];
zoomedState = ((Steema.TeeChart.Tools.ZoomTool)wChart.Chart.Tools[0]).SetCurrentZoom(Request,
zoomedState);
System.Drawing.Bitmap bmp = WebChart1.Chart.Bitmap((int)wChart.Width.Value, (int)wChart.Height.Value);
if (zoomedState == null)
{
Session.Remove(wChart.ID + "Zoomed");
Session.Add(wChart.ID + "Min", Min);
Session.Add(wChart.ID + "Max", Max);
}
else
{
if (WebChart1.Chart.Axes.Bottom.Minimum < Min || WebChart1.Chart.Axes.Bottom.Maximum > Max)
{
WebChart1.Chart.Axes.Bottom.SetMinMax(Min, Max);
}
else
{
Min = WebChart1.Chart.Axes.Bottom.Minimum;
Max = WebChart1.Chart.Axes.Bottom.Maximum;
}
Session.Add(wChart.ID + "Zoomed", zoomedState);
Session.Add(wChart.ID + "Min", Min);
Session.Add(wChart.ID + "Max", Max);
}
}
}
If it isn't a good solution for you, please let me know.
I hope will helps.
Thanks,
Re: post zoom axes values should not go out of bounds
Posted: Mon Dec 13, 2010 3:39 pm
by 15657590
Your example is kinda what I ended up doing. But one problem with that is when you zoom for a second time, the zoom does not work properly because the "zoomed state" arraylist is not changed to reflect the new axes values.
So I did this.
Code: Select all
private void CheckZoom(WebChart wChart)
{
ArrayList zoomedState = (ArrayList)Session[Request.QueryString["filename"] + "Zoomed"];
if (wChart.Chart.Tools.Count > 0)
{
zoomedState = ((Steema.TeeChart.Tools.ZoomTool)wChart.Chart.Tools[0]).SetCurrentZoom(Request, zoomedState);
if (zoomedState != null)
{
preventOutofBoundsSessionVariable(zoomedState);
preventOutofBoundsAxesVariable();
}
else
Session.Remove(Request.QueryString["filename"] + "Zoomed");
}
}
protected void preventOutofBoundsSessionVariable(ArrayList zoomedState)
{
Steema.TeeChart.Drawing.PointDouble left = (Steema.TeeChart.Drawing.PointDouble)zoomedState[0];
Steema.TeeChart.Drawing.PointDouble top = (Steema.TeeChart.Drawing.PointDouble)zoomedState[1];
Steema.TeeChart.Drawing.PointDouble right = (Steema.TeeChart.Drawing.PointDouble)zoomedState[2];
Steema.TeeChart.Drawing.PointDouble bottom = (Steema.TeeChart.Drawing.PointDouble)zoomedState[3];
if (left.X < DataCaptureTeeChart.Chart.Axes.Left.MinYValue)
left.X = DataCaptureTeeChart.Chart.Axes.Left.MinYValue;
if (left.Y > DataCaptureTeeChart.Chart.Axes.Left.MaxYValue)
left.Y = DataCaptureTeeChart.Chart.Axes.Left.MaxYValue;
if (bottom.X < DataCaptureTeeChart.Chart.Axes.Bottom.MinXValue)
bottom.X = DataCaptureTeeChart.Chart.Axes.Bottom.MinXValue;
if (bottom.Y > DataCaptureTeeChart.Chart.Axes.Bottom.MaxXValue)
bottom.Y = DataCaptureTeeChart.Chart.Axes.Bottom.MaxXValue;
zoomedState.Clear();
zoomedState.Add(left);
zoomedState.Add(top);
zoomedState.Add(right);
zoomedState.Add(bottom);
Session.Add(Request.QueryString["filename"] + "Zoomed", zoomedState);
}
protected void preventOutofBoundsAxesVariable()
{
if (DataCaptureTeeChart.Chart.Axes.Left.Minimum < DataCaptureTeeChart.Chart.Axes.Left.MinYValue)
DataCaptureTeeChart.Chart.Axes.Left.Minimum = DataCaptureTeeChart.Chart.Axes.Left.MinYValue;
if (DataCaptureTeeChart.Chart.Axes.Left.Maximum > DataCaptureTeeChart.Chart.Axes.Left.MaxYValue)
DataCaptureTeeChart.Chart.Axes.Left.Maximum = DataCaptureTeeChart.Chart.Axes.Left.MaxYValue;
if (DataCaptureTeeChart.Chart.Axes.Bottom.Minimum < DataCaptureTeeChart.Chart.Axes.Bottom.MinXValue)
DataCaptureTeeChart.Chart.Axes.Bottom.Minimum = DataCaptureTeeChart.Chart.Axes.Bottom.MinXValue;
if (DataCaptureTeeChart.Chart.Axes.Bottom.Maximum > DataCaptureTeeChart.Chart.Axes.Bottom.MaxXValue)
DataCaptureTeeChart.Chart.Axes.Bottom.Maximum = DataCaptureTeeChart.Chart.Axes.Bottom.MaxXValue;
}
Thanks for the help.
Jag
Re: post zoom axes values should not go out of bounds
Posted: Wed Dec 15, 2010 2:59 pm
by 10050769
Hello jag,
I am glad that you can solve your problem.
Thanks,