Page 1 of 1

Custom Axis Zoom

Posted: Mon Apr 13, 2009 4:58 am
by 13050300
Hi,

I have seen reply for custom axis zoom in forum http://www.teechart.net/support/viewtop ... 159e5f9db8

I am using WPF TChart (V. 3.5.3146.24806).

I have added 11 horizontal custom axis.

If i zoom first custom axis using axis.SetMinMax(min, max); the axis will set to min and max but the series point will goes outside the boundary of axis.

So please guide me how can i solve this problem.

Thanks & Regards,
Mitesh Sureja

Posted: Tue Apr 14, 2009 8:17 am
by narcis
Hi Mitesh,

Could you please send us a simple example project we can run "as-is" to reproduce the problem here?

You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.

Custom Axis Zoom

Posted: Tue Apr 14, 2009 11:02 am
by 13050300
Hi Narcís,

Thanks for your reply.

I have uploaded simple example named TChartCustomAxisZoom.zip using upload page link. You can easily reproduce problem with the sample.

In sample i have used TeeChart.WPF.dll (V. 3.5.3146.24806). You might need to add reference for TeeChart.WPF.dll.

Steps for reproduce problem:
1. Run the sample.
2. Try to zoom first custom axis.

Actual Result:
Custom axis set with axis.SetMinMax(min, max) but the first series overlaps on second series.

Expected result:
Custom axis should set as per min, max value and first series points should go outside the first axis area.

So please help me to resolve this problem.

Regards,
Mitesh

Posted: Tue Apr 14, 2009 1:42 pm
by narcis
Hi Mitesh,

Thanks for the example project. In that case you should try doing as in the All Features\Welcome !\Axes\Opaque zones in the new features demo available at TeeChart's program group.

Also notice there is a much newer version of TeeChart available at the client download area.

Custom Axis Zoom

Posted: Wed Apr 15, 2009 12:05 pm
by 13050300
Hi Narcís,

Thanks for reply.

I have tried with All Features\Welcome !\Axes\Opaque zones as explained in new features demo.

Using this I went one step ahead. But when i zoom first series, the series points will not overlap with others but other series disappears. The same thing happens with feature demo Opaque zones sample.

We expect that first should zoom but other series should not change or disappear.

I have also uploaded the sample(TChartCustomAxisZoom_Opaque.zip) for your reference.

Please help me to solve this problem.

Thanks & Regards,
Mitesh Sureja

Posted: Fri Apr 17, 2009 10:30 am
by narcis
Hi Mitesh,

Thanks for the example project. We are investigating the issue and will get back to you ASAP.

Posted: Fri Apr 17, 2009 2:51 pm
by narcis
Hi Mitesh,

Ok, to achieve what you request you can implement your project like this:

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Steema.TeeChart.WPF;
using Steema.TeeChart.WPF.Styles;
using Steema.TeeChart;

namespace TChartCustomAxisZoom
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
	public partial class Window1 : Window
	{
		Random rnd = new Random();
		TChart tChart;
		bool zoomed = false;
		private double MouseXDown, MouseYDown;
		FastLine fLine1 = new FastLine();
		FastLine fLine2 = new FastLine();
		FastLine fLine3 = new FastLine();

		public Window1()
		{
			InitializeComponent();
			InitializeChart();

		}
		Axis bottomAxis1, bottomAxis2, bottomAxis3;
		private void InitializeChart()
		{

			tChart = CreateChart();
			tChart.Zoomed += new EventHandler(tChart_Zoomed);
			tChart.UndoneZoom += new EventHandler(tChart_UndoneZoom);
			tChart.MouseDown += new MouseButtonEventHandler(tChart_MouseDown);
			fLine1.BeforeDrawValues += new PaintChartEventHandler(fLine1_BeforeDrawValues);
			fLine1.AfterDrawValues += new PaintChartEventHandler(fLine1_AfterDrawValues);

			fLine2.BeforeDrawValues += new PaintChartEventHandler(fLine1_BeforeDrawValues);
			fLine2.AfterDrawValues += new PaintChartEventHandler(fLine1_AfterDrawValues);
			fLine3.BeforeDrawValues += new PaintChartEventHandler(fLine1_BeforeDrawValues);
			fLine3.AfterDrawValues += new PaintChartEventHandler(fLine1_AfterDrawValues);

			tChart.Series.Add(fLine1);
			tChart.Series.Add(fLine2);
			tChart.Series.Add(fLine3);
			Axis bottomAxis = tChart.Axes.Bottom;
			bottomAxis1 = bottomAxis.Clone() as Axis;
			bottomAxis1.StartPosition = 0;
			bottomAxis1.EndPosition = 25;
			bottomAxis2 = bottomAxis.Clone() as Axis;
			bottomAxis2.StartPosition = 30;
			bottomAxis2.EndPosition = 55;
			bottomAxis3 = bottomAxis.Clone() as Axis;
			bottomAxis3.StartPosition = 60;
			bottomAxis3.EndPosition = 85;
			fLine1.CustomHorizAxis = bottomAxis1;
			fLine2.CustomHorizAxis = bottomAxis2;
			fLine3.CustomHorizAxis = bottomAxis3;


			FillRandomValues(fLine1);
			FillRandomValues(fLine2);
			FillRandomValues(fLine3);

			grid1.Children.Add(tChart);
		}

		void fLine1_AfterDrawValues(object sender, Steema.TeeChart.WPF.Drawing.Graphics3D g)
		{
			if (zoomed)
			{
				g.UnClip();
			}
		}

		void fLine1_BeforeDrawValues(object sender, Steema.TeeChart.WPF.Drawing.Graphics3D g)
		{
			if (zoomed)
			{
				Series s = sender as Series;
				double left = s.GetHorizAxis.IStartPos;
				double right = s.GetHorizAxis.IEndPos;
				double top = s.GetVertAxis.IStartPos;
				double bottom = s.GetVertAxis.IEndPos;
				g.ClipRectangle(left, top, right, bottom);
			}
		}

		void tChart_Zoomed(object sender, EventArgs e)
		{
			if (seriesArea != -1)
			{
				Axis axis = tChart.Series[seriesArea].GetHorizAxis;
				axis.Automatic = false;

				double min = axis.CalcPosPoint(tChart.Series[seriesArea].Chart.Zoom.x0);
				double max = axis.CalcPosPoint(tChart.Series[seriesArea].Chart.Zoom.x1);
				axis.SetMinMax(min, max);

				zoomed = true;
			}
		}
		private TChart CreateChart()
		{
			TChart tChart = new TChart();
			tChart.Aspect.View3D = false;
			tChart.Legend.Visible = false;
			tChart.Aspect.ClipPoints = false;
			tChart.Zoom.Allow = true;
			tChart.Zoom.Direction = ZoomDirections.Horizontal;
			return tChart;
		}
		private double[] FillRandomValues(FastLine fLine)
		{
			double[] randomValues = new double[100];
			for (int i = 0; i < 100; i++)
			{
				fLine.Add(rnd.NextDouble(), rnd.NextDouble());
			}
			return randomValues;
		}

		void tChart_UndoneZoom(object sender, EventArgs e)
		{
			zoomed = false;
			for (int i = 0; i < tChart.Series.Count; i++)
			{
				tChart[i].CustomHorizAxis.Automatic = true;
			}
		}

		int seriesArea;

		private int GetSeriesArea(Point p)
		{
			if (p.X > bottomAxis1.IStartPos && p.X < bottomAxis1.IEndPos)
			{
				return 0;
			}
			else if (p.X > bottomAxis2.IStartPos && p.X < bottomAxis2.IEndPos)
			{
				return 1;
			}
			else if (p.X > bottomAxis3.IStartPos && p.X < bottomAxis3.IEndPos)
			{
				return 2;
			}
			else
			{
				return -1;
			}
		}


		void tChart_MouseDown(object sender, MouseButtonEventArgs e)
		{
			Point p = e.GetPosition(tChart);
			MouseXDown = p.X;
			MouseYDown = p.Y;

			seriesArea = GetSeriesArea(p);
		}
	}
}