Page 1 of 1
Keep Zoom on Custom axes
Posted: Thu Apr 28, 2011 1:52 am
by 15657926
Hi, I am using webchart, I have some custom Y axes, when I zoom in on the chart I make the follow in my CheckZoom function:
Code: Select all
...
for (int c = 0; c < this.CurvesWebChart.Chart.Axes.Custom.Count; c++)
{
Axis axis = this.CurvesWebChart.Chart.Axes.Custom[c];
double y1 = axis.CalcPosPoint(this.CurvesWebChart.Chart.Zoom.y1);
double y0 = axis.CalcPosPoint(this.CurvesWebChart.Chart.Zoom.y0);
axis.SetMinMax(y1, y0);
}
...
When I press a button and the page raise a postback, in my CheckZoom function I always get "0" in y1 and y0.
How can I keep the zoom when I press a button?
Thank you in advance.
Re: Keep Zoom on Custom axes
Posted: Thu Apr 28, 2011 11:45 am
by 10050769
Hello Ternaris,
I recommend you that take a look in TeeChart ASP.net Demo concretely in Interacting with Charts\Zooming\Zoming on WebForm. If you have any problems, please let me know.
Thanks,
Re: Keep Zoom on Custom axes
Posted: Thu Apr 28, 2011 10:29 pm
by 15657926
Hello Sandra,
I saw your Demo but It doesn't use custom axes. I use custom axes with automatic size, Do you have an example with custom axes?
Thank you.
Re: Keep Zoom on Custom axes
Posted: Fri Apr 29, 2011 10:20 am
by 10050769
Hello Ternaris,
You need know that if you work with WebChart and you want do zoom you have to use ZoomTool, so you always need utilize properties of ZoomTool. I have made a simple example that use custom axis and ZoomTool and save the states of zoom to doesn't lose these and I think you can do something as next:
Code: Select all
bool zoomed;
Steema.TeeChart.Styles.FastLine series1, series2, series3;
Steema.TeeChart.Axis bottomAxis1, bottomAxis2, bottomAxis3;
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 = WebChart1.Chart;
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;
series1 = new FastLine(ch1);
series2 = new FastLine(ch1);
series3 = new FastLine(ch1);
series1.FillSampleValues();
series2.FillSampleValues();
series3.FillSampleValues();
Steema.TeeChart.Axis bottomAxis = ch1.Axes.Bottom;
bottomAxis1 = bottomAxis.Clone() as Steema.TeeChart.Axis;
bottomAxis1.StartPosition = 0;
bottomAxis1.EndPosition = 25;
bottomAxis2 = bottomAxis.Clone() as Steema.TeeChart.Axis;
bottomAxis2.StartPosition = 30;
bottomAxis2.EndPosition = 55;
bottomAxis3 = bottomAxis.Clone() as Steema.TeeChart.Axis;
bottomAxis3.StartPosition = 60;
bottomAxis3.EndPosition = 85;
//series1.CustomHorizAxis = bottomAxis1;
ch1.Axes.Bottom.EndPosition = 25;
series2.CustomHorizAxis = bottomAxis2;
series3.CustomHorizAxis = bottomAxis3;
ch1.Panel.MarginBottom = 10;
ch1.Export.Template.IncludeData = true;
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);
CheckZoom(WebChart1);
WebChart1.Chart.Invalidate();
}
}
private void CheckZoom(Steema.TeeChart.Web.WebChart WebChart1)
{
Steema.TeeChart.Chart ch1 = WebChart1.Chart;
System.Collections.ArrayList zoomedState = (System.Collections.ArrayList)Session[WebChart1.ID + "Zoomed"];
zoomedState = ((Steema.TeeChart.Tools.ZoomTool)WebChart1.Chart.Tools[0]).SetCurrentZoom(Request,
zoomedState);
if (zoomedState == null)
{
Session.Remove(WebChart1.ID +"Zoomed");
zoomed = false;
for (int i = 0; i < WebChart1.Chart.Series.Count; i++ )
{
if (ch1[i].GetVertAxis.IsCustom())
{
ch1[i].CustomHorizAxis.Automatic = true;
}
}
}
else
{
Session.Add(WebChart1.ID + "Zoomed", zoomedState);
zoomed = true;
for (int i = 0; i < ch1.Series.Count; i++ )
{
Steema.TeeChart.Axis axis = ch1[i].GetHorizAxis;
if (axis.IsCustom())
{
axis.SetMinMax(ch1.Axes.Bottom.Minimum, ch1.Axes.Bottom.Maximum);
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
WebChart1.AutoPostback=true;
}
Could you tell if previous code help you to find a good solution?
Thanks,
Re: Keep Zoom on Custom axes
Posted: Sat Apr 30, 2011 4:26 am
by 15657926
Hello Sandra, Thank you for your example, It works great.
I have the problem that each Y custom axis has different scale, and I can not use the Minimum and Maximum value of a specific axis as you do in your example...
Code: Select all
...
axis.SetMinMax(ch1.Axes.Bottom.Minimum, ch1.Axes.Bottom.Maximum);
...
Another problem is that I use a button to add or remove series from the chart (and maybe add or remove axes), here is when I have problems to keep the zoom because when I call CheckZoom() in button_Click() I always get "0" in y1 and y0, However, if I call CheckZoom() in chart_AfterDraw() I get the correct values for y1 and y0, but the y-axes don't rescale.
This is part of my CheckZoom():
Code: Select all
...
for (int c = 0; c < this.CurvesWebChart.Chart.Axes.Custom.Count; c++)
{
Axis axis = this.CurvesWebChart.Chart.Axes.Custom[c];
double y1 = 0;
double y0 = 0;
if (applyNewZoom)//user makes zoom
{//this works great...
y1 = axis.CalcPosPoint(this.CurvesWebChart.Chart.Zoom.y1);
y0 = axis.CalcPosPoint(this.CurvesWebChart.Chart.Zoom.y0);
//save last zoomY1 and zoomY0
this.lastZoomY1 = this.CurvesWebChart.Chart.Zoom.y1;
this.lastZoomY0 = this.CurvesWebChart.Chart.Zoom.y0;
}
else//user pressed button to add/remove series, keep zoom using lastZoomY1 and lastZoomY0 because this.CurvesWebChart.Chart.Zoom.y1 and this.CurvesWebChart.Chart.Zoom.y0 are "0" at this momment
{//here I get correct values only when CheckZoom() is called from chart_AfterDraw(), but axes don't rescale on chart...
y1 = axis.CalcPosPoint(this.lastZoomY1);
y0 = axis.CalcPosPoint(this.lastZoomY0);
}
axis.SetMinMax(y1, y0);
}
...
Am I doing something wrong?
How can I keep the zoom in this case?
Thank you.
Re: Keep Zoom on Custom axes
Posted: Mon May 02, 2011 12:36 pm
by 10050769
Hello Ternaris,
I have the problem that each Y custom axis has different scale, and I can not use the Minimum and Maximum value of a specific axis as you do in your example...
You can try to use SetMinMax() for each custom axis as different scale, changing next line:
Code: Select all
...
axis.SetMinMax(ch1.Axes.Bottom.Minimum, ch1.Axes.Bottom.Maximum);
...
To below lines:
Code: Select all
...
axis.SetMinMax(ch1[i].CustomHorizAxis.Minimum, ch1[i].CustomHorizAxis.Maximum+10);
...
Another problem is that I use a button to add or remove series from the chart (and maybe add or remove axes), here is when I have problems to keep the zoom because when I call CheckZoom() in button_Click() I always get "0" in y1 and y0, However, if I call CheckZoom() in chart_AfterDraw() I get the correct values for y1 and y0, but the y-axes don't rescale.
This is part of my CheckZoom():
...
Am I doing something wrong?
How can I keep the zoom in this case?
I think can help you, use WebChart.Chart.Invalidate(); or System.Drawing.Bitmap bitmap = WebChart1.Chart.Bitmap((int)WebChart1.Width.Value,(int)WebChart1.Height.Value); to repaint chart. Please, could you confirm us if my recommendations solve your problems?
I hope will helps.
Thanks,
Re: Keep Zoom on Custom axes
Posted: Tue May 03, 2011 12:04 am
by 15657926
Hello Sandra, thank you for your recommendation.
I tried it in your example, but it doesn't work correctly, because x-axes don't rescale, only increase in 10.
I found a solution for me, I don't know if it is the best way. When I zoom in the chart I calculate the percentage of zoom represents in Y, and I save it. When I add another serie with another axis, I calculate y0 an y1 for this axis based on saved zoom percentage.
If you know a better solution, It would be great to know.
Thank you.