get EXACT X-axis date-time values when user zooms the chart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Vikas Aggarwal
Newbie
Newbie
Posts: 14
Joined: Thu Aug 31, 2006 12:00 am

get EXACT X-axis date-time values when user zooms the chart

Post by Vikas Aggarwal » Fri Sep 29, 2006 1:11 pm

We are using TeeChart.NET version 2 (Build 2.0.2306.26231). Please find attached sample code and database. This code plots 2 series by pulling data from Access database and prints the X-axis labels in text file. Please edit the code to give convenient path to the sample database and text file.

Our main goal is to get EXACT start date-time and end date-time from X-axis when user selects area to "zoom". For that purpose, we intend to have labels on X-axis with one second margin. So that after zoom, we could retrieve EXACT date-time of zoom area from "FirstVisibleIndex" and "LastVisibleIndex" properties.

We tried the solution you provided as below:
trendChart.Axes.Bottom.Increment = (double)Steema.TeeChart.DateTimeSteps.OneSecond;
trendChart.Axes.Bottom.Labels.Separation = 0;
//////////Zero separation to have all labels. As our requirement, we only need to show start and end label on X-axis, so we do not worry about cluttered variables [we have taken that care in "GetAxisLabel" event]

If you see text file of labels, it only prints labels what are there in database, and not labels with difference of one second. It seems TeeChart calculates "how many" labels to print before rendering the control.

Would you please guide us in how to get EXACT X-axis date-time values when user zooms the chart area.

here is code

Code: Select all

using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using Steema.TeeChart;
using Steema.TeeChart.Web;
using Steema.TeeChart.Tools;

namespace Lilly.B130BatchTools
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected Steema.TeeChart.Web.WebChart webChart;
		private int m_maxCount = 0;
		private const string dbPath = @"c:\inetpub\wwwroot\db1.mdb";
		private const string filePath = @"c:\inetpub\wwwroot\labels.txt";
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			Steema.TeeChart.Styles.Line lineValue = null;
			Steema.TeeChart.Chart trendChart = null;
			Axis multiAxes = null;

			if (File.Exists(filePath))
			{
				File.Delete(filePath);
			}
			webChart.Clear();
			trendChart = webChart.Chart;
			trendChart.Legend.Alignment = 
				Steema.TeeChart.LegendAlignments.Top;

			trendChart.Axes.Bottom.Title.Text = "Time";
			trendChart.Axes.Bottom.Title.Font.Color = Color.DarkGray;
			trendChart.Axes.Bottom.Labels.Angle = 90;
			trendChart.Axes.Bottom.Increment = 
				(double)Steema.TeeChart.DateTimeSteps.OneSecond;
			trendChart.Axes.Bottom.Labels.Separation = 0;

			trendChart.Axes.Left.Title.Text = "Point Values";
			trendChart.Axes.Left.Title.Font.Color = Color.DarkGray;
				
			trendChart.Aspect.View3D = false;
			trendChart.Walls.Visible = false;
			webChart.Chart.Series.RemoveAllSeries();

			string query = "SELECT PointValue, TimeValue FROM Point{0}";
			OleDbConnection cn = new OleDbConnection(
				"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbPath);
			cn.Open();
			DataSet dataSet = null;
			OleDbDataAdapter da = null;
			DataTable table = null;
			m_maxCount = 0;
				
			for (int i = 1; i < 3; i++)
			{
				query = String.Format(query, i.ToString());
				da = new OleDbDataAdapter(query, cn);
				dataSet = new DataSet();
				da.Fill(dataSet);
				table = dataSet.Tables[0];

				if (table.Rows.Count > m_maxCount)
				{
					m_maxCount = table.Rows.Count;
				}

				lineValue = new Steema.TeeChart.Styles.Line();
				lineValue.Title = "Point" + i.ToString();
				lineValue.YValues.DataMember = 
					table.Columns["PointValue"].ToString();
				lineValue.XValues.DateTime = true;
				lineValue.LabelMember = table.Columns["TimeValue"].ToString();
				lineValue.XValues.DataMember = 
					table.Columns["TimeValue"].ToString();
				lineValue.DataSource = table;
				trendChart.Series.Add(lineValue);
				
				if (i == 1)
				{
					trendChart.Axes.Left.AxisPen.Color = 
						lineValue.Color;
				}
				else
				{
					multiAxes = new Axis(
						false, false, webChart.Chart);
					multiAxes.AxisPen.Color = lineValue.Color;
					multiAxes.PositionUnits = PositionUnits.Percent;
					multiAxes.RelativePosition = 6 * (i-1);
					webChart.Chart.Axes.Custom.Add(multiAxes);
					lineValue.CustomVertAxis = multiAxes;
				}
			}

			cn.Close();
			Steema.TeeChart.Themes.ColorPalettes.ApplyPalette(
				trendChart.Chart,7);
			webChart.Chart.Legend.LegendStyle = 
				Steema.TeeChart.LegendStyles.Series;	
			webChart.Chart.Header.Visible = false;
			webChart.Visible = true;
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.webChart.GetAxisLabel += new Steema.TeeChart.GetAxisLabelEventHandler(this.webChart_GetAxisLabel);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void webChart_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
		{
			if(((Steema.TeeChart.Axis)sender).Equals(webChart.Chart.Axes.Bottom))
			{
				StreamWriter sw = File.AppendText(filePath);
				sw.WriteLine(e.LabelText);
				sw.Close();
				if (e.ValueIndex > 0 && e.ValueIndex < (m_maxCount - 1))
				{
					e.LabelText = "";
				}
			}
		}
	}
}

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Sep 29, 2006 2:51 pm

Hi Vikas,

Where did you attach the code and database you mentioned? Could you please post it at news://www.steema.net/steema.public.attachments newsgroup?

Thanks in advance.
Best Regards,
Narcís Calvet / 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

Vikas Aggarwal
Newbie
Newbie
Posts: 14
Joined: Thu Aug 31, 2006 12:00 am

Problem in putting attachment

Post by Vikas Aggarwal » Tue Oct 03, 2006 3:00 pm

Narcis,

I have problem putting attachment on the newsgroup. Can you let me know an email id where I can send the attachment?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Oct 05, 2006 10:37 am

Hi Vikas,

Thanks for the example.
Our main goal is to get EXACT start date-time and end date-time from X-axis when user selects area to "zoom". For that purpose, we intend to have labels on X-axis with one second margin. So that after zoom, we could retrieve EXACT date-time of zoom area from "FirstVisibleIndex" and "LastVisibleIndex" properties.


I can reproduce what you reported. However we don't understand what are you exactly trying to get here. TeeChart doesn't allow drawing the labels if there are too many in the chart and they overlap each other. When zooming axis are automatically re-scaled and if the Increment settings can be achieved axes scales are drawn accordingly.

Could you please send us a project we can run "as-is" to reproduce what you are trying to achieve here?

Thanks in advance.
Best Regards,
Narcís Calvet / 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

montekristo
Newbie
Newbie
Posts: 2
Joined: Mon Oct 16, 2006 12:00 am

Zooming and datetime bottom axis

Post by montekristo » Thu Mar 22, 2007 4:09 pm

Hello.
I am trying to have more or less the same effect in a window application.

The problem is that in the tChart_Zoomed event I reload the
data, set the Automatic for the bottom axis to false and the
minimum and maximum values (datetimes) and the already
loaded value series do not appear...
Even though their values seem to get loaded correctly since I handle the
left axis and I get the expected increments and results for that axis.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Mar 22, 2007 4:21 pm

Hi montekristo,

Could you please send us a simple example project we can run "as-is" to reproduce the problem here? You can either post it at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.
Best Regards,
Narcís Calvet / 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

montekristo
Newbie
Newbie
Posts: 2
Joined: Mon Oct 16, 2006 12:00 am

Post by montekristo » Fri Mar 23, 2007 9:20 am

I am afraid the app is a little to complex and I do not want to spend too
much time writing code only for upload.

The thing is no matter if the number of points for the data series is equal
or less than the number of points set for a series which contains
datetime values, if the Automatic property set to true for the bottom
axis or/and the bottomAxis.SetMinMax mathod is used with
datetime values the series do not appear even though it seems that their
values are being loaded succesfully.

This is really annoying because quick response time for the representation
of the graph is quite crucial and now I am writing code in order to
emulate the labeling of the bottom axis. Something which is going to consume extra processing time. I am using the latest stable version of
the .net 2 dll

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Mar 23, 2007 12:26 pm

Hi montekristo,

Ok, then you may be interested in trying something like this:

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}

		private void InitializeChart()
		{
			int length = 60;
			DateTime now = DateTime.Now;
			Random rnd = new Random();

			for (int i = 0; i < length; i++)
			{
				line1.Add(now, rnd.NextDouble());
				now = now.AddMinutes(1);
			}

			tChart1.Aspect.View3D = false;
		}

		private bool first = true;
		private DateTime newDate;

		private void tChart1_GetNextAxisLabel(object sender, Steema.TeeChart.GetNextAxisLabelEventArgs e)
		{
			if ((sender as Steema.TeeChart.Axis).Equals(tChart1.Axes.Bottom))
			{
				e.Stop = false;

				if (first)
				{
					double value = e.LabelValue;
					DateTime date = DateTime.FromOADate(value);
					newDate = new DateTime(date.Year, date.Month, date.Day, date.Hour, 0, 0);
					if (date.Minute >= 15)
					{
						newDate = newDate.AddMinutes(15);
					}
					else if (date.Minute >= 30)
					{
						newDate = newDate.AddMinutes(30);
					}
					else if (date.Minute >= 45)
					{
						newDate = newDate.AddMinutes(45);
					}
					first = false;
				}
				else
				{
					newDate = newDate.AddMinutes(15);
				}
		
				switch (e.LabelIndex)
				{
					case 0:
						//e.LabelValue = newDate.ToOADate();
						e.LabelValue = tChart1.Axes.Bottom.CalcPosPoint(tChart1.Axes.Left.Position);
						break;
					case 1:
						e.LabelValue = newDate.ToOADate();
						break;
					case 2:
						e.LabelValue = newDate.ToOADate();
						break;
					case 3:
						e.LabelValue = newDate.ToOADate();
						break;
					case 4:
						e.LabelValue = newDate.ToOADate();
						break;
					case 5:
						e.LabelValue = newDate.ToOADate();
						break;
					case 6:
						//e.LabelValue = newDate.ToOADate();
						e.LabelValue = tChart1.Axes.Bottom.CalcPosPoint(tChart1.Axes.Bottom.IEndPos);
						break;
					default:
						e.Stop = true;
						first = true;
						break;
				}
			} 
		}
Best Regards,
Narcís Calvet / 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

Post Reply