DateTime x axis labels ambiguous at small ranges

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Michael
Newbie
Newbie
Posts: 6
Joined: Tue Jul 13, 2004 4:00 am
Location: South Africa

DateTime x axis labels ambiguous at small ranges

Post by Michael » Thu Oct 20, 2005 12:13 pm

Hi

I'm plotting graphs wide widely varying x-axis ranges, and the x-axis is using DateTime values.

The automatic ticks and labels work very well indeed 90% of the time, but I am experiencing some problems at smaller ranges.

I have 3 specific problems that I was hoping there might be a good work-around for...

1) the x-axis labels aren't linked to the system regional settings... my time format is 13:58, but the x-axis labels still come out as 1:58 PM.

2) at small ranges (say, 5 seconds between min and max) the time format chosen automatically is still hh:mm, so one gets a series of x-axis labels that all say "11:19", "11:19" etc.

3) when one chooses a smaller range than that, say 50ms, the labels are very sparsely placed, because it is still placing labels only every 1000ms. Labels appear again at 1ms intervals only when I'm down to a range of say 10ms. So there is an unusual 3-orders-of-magnitude between automatically-chosen intervals in this area.

Now, the main thing is that the automatic labelling works very well indeed, and I certainly don't want to circumvent it and replace it with my own code completely, so I'm wondering what the best way to solve these problems would be.

The code I'm using as an example is:

Code: Select all

this.chart = new Steema.TeeChart.TChart();
			this.chart.Location = new System.Drawing.Point(0, 0);
			this.chart.Name = "chart";
			this.chart.Size = new System.Drawing.Size(576, 405);
			this.chart.TabIndex = 0;
			this.Controls.Add(this.chart);

			double dNow = DateTime.Now.ToOADate();
			
			FastLine line = new FastLine();
			line.XValues.DateTime = true;
			chart.Series.Add(line);

			for (double d=0; d<1; d+=0.1) 
			{
				line.Add(dNow+d, d*d);
			}


Just zoom in :)

Thanks

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 Oct 21, 2005 1:59 pm

Hi Michael,
1) the x-axis labels aren't linked to the system regional settings... my time format is 13:58, but the x-axis labels still come out as 1:58 PM.

2) at small ranges (say, 5 seconds between min and max) the time format chosen automatically is still hh:mm, so one gets a series of x-axis labels that all say "11:19", "11:19" etc.
Both problems are solved using DateTimeFormat as here:

Code: Select all

chart.Axes.Bottom.Labels.DateTimeFormat="HH:mm:ss.fff";
3) when one chooses a smaller range than that, say 50ms, the labels are very sparsely placed, because it is still placing labels only every 1000ms. Labels appear again at 1ms intervals only when I'm down to a range of say 10ms. So there is an unusual 3-orders-of-magnitude between automatically-chosen intervals in this area.

Now, the main thing is that the automatic labelling works very well indeed, and I certainly don't want to circumvent it and replace it with my own code completely, so I'm wondering what the best way to solve these problems would be.
This is a problem I've been able to reproduce here. I've added this (TF02011034) to our defect list to be fixed for future releases.
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

Michael
Newbie
Newbie
Posts: 6
Joined: Tue Jul 13, 2004 4:00 am
Location: South Africa

Post by Michael » Tue Oct 25, 2005 10:16 am

Hi Narcis

Thanks for the feedback... I don't want to force the label format all the time, because it disables TeeChart's automatic labelling.

So I've made it work only for smaller ranges, as below.

I can't seem to find out exactly what the label width should be -- I think it's calculated internally somewhere. This seems to work pretty well though, although it's not flawless.

Anyway, I call this on BeforeDrawAxis.

Code: Select all

private void SetupXAxisLabelFormat() 
		{
			Steema.TeeChart.Axis xAxis = Axes.Bottom;
			// calculate the estimated increment size, based on a label width estimate of 45...
			// thru testing, this seems to be about right
			double dInc = xAxis.CalcXYIncrement(45);
			
			if (dInc < 1.0/24.0/60.0/60.0)  // 1 second
			{
				xAxis.Labels.DateTimeFormat = "HH:mm:ss.fff";
			}
			else if (dInc < 1.0/24.0/60.0) // less than minute
			{
				xAxis.Labels.DateTimeFormat =  "HH:mm:ss";
			}
			else if (dInc < 1.0/24.0) // less than an hour
			{
				xAxis.Labels.DateTimeFormat =  "HH:mm";
			} 
			else if (dInc < 1.0) // less than a day
			{
				xAxis.Labels.DateTimeFormat = "HH:mm";
			}
			else 
			{
				// This is the default -- TeeCharts automatic choice of label format
				xAxis.Labels.DateTimeFormat = string.Empty;
			}
		}
Thanks for the help, and looking forward to a future release where the millisecond to second jump is fixed ;)

~m

Post Reply