Page 1 of 5

custom AxisLabels overlap

Posted: Tue Oct 18, 2005 6:00 pm
by 8884430
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?

Posted: Wed Oct 19, 2005 8:58 am
by narcis
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;

Posted: Thu Oct 20, 2005 3:28 pm
by 8884430
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.

Posted: Fri Oct 21, 2005 1:32 pm
by narcis
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?

turn 90 degrees

Posted: Fri Oct 21, 2005 1:53 pm
by 8121612
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

Posted: Fri Oct 21, 2005 3:06 pm
by 8884430
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?

exception

Posted: Mon Oct 24, 2005 9:36 am
by 8121612
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

Posted: Mon Oct 24, 2005 2:08 pm
by narcis
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;
				}
			}
		}

Posted: Wed Oct 26, 2005 4:13 pm
by 8884430
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.

Posted: Wed Nov 02, 2005 12:42 pm
by 8121612
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;
}
}
}

Posted: Wed Nov 02, 2005 1:01 pm
by narcis
Hi Werner,

With which TeeChart version have you tested that?

Thanks in advance.

Posted: Wed Nov 02, 2005 1:11 pm
by 8121612
Hi Narcis!

I have version 1.1.2117.41652 installed.

Nice regards
Werner

Posted: Wed Nov 02, 2005 1:19 pm
by 8121612
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

Posted: Wed Nov 02, 2005 2:10 pm
by narcis
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.

Posted: Wed Nov 02, 2005 2:24 pm
by 8121612
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.