custom AxisLabels overlap

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
johnk
Newbie
Newbie
Posts: 8
Joined: Mon Oct 04, 2004 4:00 am

custom AxisLabels overlap

Post by johnk » Tue Oct 18, 2005 6:00 pm

I have a chart with custom log labels on the left and bottom axis.
My problem is that when the chart is resized the labels can overlap each other.
I looked at the demo All Features -> Welcome ! -> Axes -> Labels -> Custom Labels and Custom logarithmic labels and they overlap as well.

I've tried using the GetAxisDrawLabel event but how do I detect if the label being drawn is going to overlap one of the adjacent labels?

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

Post by Narcís » Wed Oct 19, 2005 8:58 am

Hi johnk,

I haven't been able to reproduce what you report. Could you please tell me the exact steps to reproduce this behaviour?

BTW: You could try avoid overlapping labels by incresing its size or axis increment:

Code: Select all

	tChart1.Axes.Bottom.Labels.CustomSize=30;
	tChart1.Axes.Bottom.Increment=10;
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

johnk
Newbie
Newbie
Posts: 8
Joined: Mon Oct 04, 2004 4:00 am

Post by johnk » Thu Oct 20, 2005 3:28 pm

To see this problem you can start the Steema demo and look at
Welcome !\Axes\Labels\Custom labels. There are custom labels on the left axis. When you resize the application so that the Chart becomes smaller you can see that the bottom axis will drop labels when they get too close. The left axis however does not drop any labels and they will overlap.
I tried both CustomSize and Increment and they have no affect.

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:32 pm

Hi johnk,

Thanks for the information. I've been able to reproduce the problem here. Which behaviour do you suggest for this? Which of the 4 labels would you expect to see when the chart is very small?
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

Werner Kratochwil
Newbie
Newbie
Posts: 17
Joined: Mon Dec 08, 2003 5:00 am

turn 90 degrees

Post by Werner Kratochwil » Fri Oct 21, 2005 1:53 pm

Hi johnk,

Thanks for the information. I've been able to reproduce the problem here. Which behaviour do you suggest for this? Which of the 4 labels would you expect to see when the chart is very small?
Hi all,

I got the same problem as well.
I'd suggest to turn the label 90 degrees, if you can't fit it in.
How about that?

Nice regards
Werner

johnk
Newbie
Newbie
Posts: 8
Joined: Mon Oct 04, 2004 4:00 am

Post by johnk » Fri Oct 21, 2005 3:06 pm

Turning them 90 degrees will not work for my situation. I'd like a way to detect if a label will overlap another label. Then I can apply my own algorithm to the labels.
I was looking at GetAxisDrawLabel but there is no way for me to tell what the previous label and the next label are and if they will overlap with the current label. Is there anything obvious that I'm missing?

Werner Kratochwil
Newbie
Newbie
Posts: 17
Joined: Mon Dec 08, 2003 5:00 am

exception

Post by Werner Kratochwil » Mon Oct 24, 2005 9:36 am

Probably it would be best to throw an exception.
So one could truncate or turn 90 degrees or do whatever....
Would that be possible?

Or would it be possible to still show them - even if they overlap?

Nice regards
Werner

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

Post by Narcís » Mon Oct 24, 2005 2:08 pm

Hello everyone,

You could implement something like the code below in the OnAfterDraw event and do what you want when labels overlap.

Code: Select all

		private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
		{ 			
			tChart1.Header.Text="";

			Steema.TeeChart.AxisLabelItem CurrentLabel, PreviousLabel;	
			for (int i=1; i<tChart1.Axes.Left.Labels.Items.Count; ++i)
			{ 
				CurrentLabel = tChart1.Axes.Left.Labels.Items[i];
				PreviousLabel = tChart1.Axes.Left.Labels.Items[i-1];

				tChart1.Header.Text=tChart1.Header.Text+" "+CurrentLabel.Top.ToString();

				if (CurrentLabel.Top+CurrentLabel.Height == PreviousLabel.Top)
				{
					CurrentLabel.Visible=false;
				}
			}
		}
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

johnk
Newbie
Newbie
Posts: 8
Joined: Mon Oct 04, 2004 4:00 am

Post by johnk » Wed Oct 26, 2005 4:13 pm

Thanks for the help but I ended up using GetAxisDrawLabel.
In the eventargs for this event I have the label text and its location. I look up the label in my AxisLabelItems collection so I can find the previous and next labels. I get the rectangle for next and previous and see if they overlap. Then all I do is set the flag in the EventArgs called DrawLabel to true or false.

Werner Kratochwil
Newbie
Newbie
Posts: 17
Joined: Mon Dec 08, 2003 5:00 am

Post by Werner Kratochwil » Wed Nov 02, 2005 12:42 pm

Hi narcis!

Thanks for your example.
I tried your code, but tChart1.Chart.Axes.Bottom.Labels.Items.Count is zero. What am I doing wrong?

Besides you might want to correct these errors I found in your example (for other users with the same problem)
- instead of tChart1 one should use tChart1.Chart instead
- Is it necessary to reset the header text as well or is just an example of yours?
- CurrentLabel does not have the property Height or Width, you need to use CurrentLabel.Size instead

Thanks
Werner
Hello everyone,

You could implement something like the code below in the OnAfterDraw event and do what you want when labels overlap.

Code:
private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
tChart1.Header.Text="";

Steema.TeeChart.AxisLabelItem CurrentLabel, PreviousLabel;
for (int i=1; i<tChart1.Axes.Left.Labels.Items.Count; ++i)
{
CurrentLabel = tChart1.Axes.Left.Labels.Items;
PreviousLabel = tChart1.Axes.Left.Labels.Items[i-1];

tChart1.Header.Text=tChart1.Header.Text+" "+CurrentLabel.Top.ToString();

if (CurrentLabel.Top+CurrentLabel.Height == PreviousLabel.Top)
{
CurrentLabel.Visible=false;
}
}
}

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

Post by Narcís » Wed Nov 02, 2005 1:01 pm

Hi Werner,

With which TeeChart version have you tested that?

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

Werner Kratochwil
Newbie
Newbie
Posts: 17
Joined: Mon Dec 08, 2003 5:00 am

Post by Werner Kratochwil » Wed Nov 02, 2005 1:11 pm

Hi Narcis!

I have version 1.1.2117.41652 installed.

Nice regards
Werner

Werner Kratochwil
Newbie
Newbie
Posts: 17
Joined: Mon Dec 08, 2003 5:00 am

Post by Werner Kratochwil » Wed Nov 02, 2005 1:19 pm

Probably it is the same problem as described in

http://www.teechart.net/support/modules ... c5657e4791

I will also try with GetAxisDrawLabel I guess.

Nice regards
Werner

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

Post by Narcís » Wed Nov 02, 2005 2:10 pm

Hi Werner,

If you are not using custom labels that will be the matter.
- instead of tChart1 one should use tChart1.Chart instead


When do you need to use this, you should be able to use tChart1.
- Is it necessary to reset the header text as well or is just an example of yours?


It's just my example because I didn't want the header having several lines.
- CurrentLabel does not have the property Height or Width, you need to use CurrentLabel.Size instead


Those properties are available in TeeChart for .NET v2.
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

Werner Kratochwil
Newbie
Newbie
Posts: 17
Joined: Mon Dec 08, 2003 5:00 am

Post by Werner Kratochwil » Wed Nov 02, 2005 2:24 pm

I tried to work with GetAxisDrawLabel, but I could not get it to work.
Could you please give me some code snippets of how to do that?

I also tried what is described in the FAQ at:

http://www.teechart.net/support/modules ... 0Labelling

But when I do:

Code: Select all

WebChartProdukt.Chart.Axes.Bottom.Automatic = false; 
it only displays the first value.

When I try

Code: Select all

WebChartProdukt.Chart.Dock = System.Windows.Forms.DockStyle.Fill; 
it does not find Dock

Now all labels are displayed and overlap if there is too less space.

Post Reply