Page 1 of 1

find out X and Y pos of labels

Posted: Tue Nov 22, 2005 2:55 pm
by 9639216
Hi!

Is it possible to find out X and Y position of all labels before drawing?

The only point I know is Bottom_GetAxisDrawLabel and there you can only get one xy-position at a time.

I need this to check for overlapping labels.

Nice regards
Werner

Posted: Wed Nov 23, 2005 12:20 pm
by narcis
Hi Werner,

Yes, for that you need to use custom labels and use them as shown here:

Code: Select all

		private void tChart1_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
		{
			Steema.TeeChart.AxisLabelItem CustLabel = tChart1.Axes.Bottom.Labels.Items[e.ValueIndex];
			CustLabel.Left=0;
			CustLabel.Top=0;
		}

ASP.NET page

Posted: Wed Nov 23, 2005 2:38 pm
by 9639216
Hey Narcis!

Are you sure this works for ASP.NET pages as well?

At my program e.ValueIndex is -1 and
WebChart.Chart.Axes.Bottom.Labels.Items[0].Left is 0.

Any other ideas?

Werner

Posted: Thu Nov 24, 2005 2:33 pm
by narcis
Hi Werner,

Yes, this is because e.ValueIndex is only for standard labels. For positioning custom labels GetAxisLabel is not necessary, you should add them as shown in the snippet below and place them on the chart according to previous labels positions and using Top, Left, Width and Height properties.

Code: Select all

		private void Page_Load(object sender, System.EventArgs e)
		{
			WebChart1.Chart.Series[0].FillSampleValues();

			WebChart1.Chart.Axes.Left.Labels.Items.Clear();

//			Add custom labels like this:
			Steema.TeeChart.AxisLabelItem a = WebChart1.Chart.Axes.Left.Labels.Items.Add(-100);
			a.Transparent=false;
			a.Color=Color.Blue;
			a.Transparency=50;

//			Do the overlapping calculation here and position the labels accordingly 
//			using the properties below
//			a.Top=;
//			a.Left=;
//			a.Width=;
//			a.Height=;
		}

Aha

Posted: Thu Nov 24, 2005 2:42 pm
by 9639216
Ahh. Now - finally - we are getting there.
Why did it take so long to get this across????

I'll try this and get back to you, if I still have troubles.

Cheers for the info
Werner

still zero

Posted: Mon Nov 28, 2005 12:53 pm
by 9639216
If I do
Steema.TeeChart.AxisLabelItem label = WebChartProdukt.Chart.Axes.Bottom.Labels.Items.Add(nr,bez);
db.log.WriteDebug("Neue LabelPos: "+label.Left+"/"+label.Top);
label.Left and label.Top is still zero.

Is there supposed to be a value set if I add the label as done above?

Regards
Werner

Posted: Tue Nov 29, 2005 2:40 pm
by narcis
Hi Werner,

No, it works when this is implemented after the chart is drawn. To force the chart being repainted the bitmap trick below is necessary:

Code: Select all

		private void Button1_Click(object sender, System.EventArgs e)
		{
			Bitmap bmp = WebChart1.Chart.Bitmap();
			for (int i=0;i<WebChart1.Chart.Axes.Left.Labels.Items.Count;++i)
			{
				Steema.TeeChart.AxisLabelItem Current = WebChart1.Chart.Axes.Left.Labels.Items[i];
				Label1.Text=Label1.Text+" "+Current.Left.ToString()+"/"+Current.Top.ToString();
			}
		}

I am confused

Posted: Tue Nov 29, 2005 3:26 pm
by 9639216
What do you want me to do?

I did

Code: Select all

Steema.TeeChart.AxisLabelItem label = WebChartProdukt.Chart.Axes.Bottom.Labels.Items.Add(nr,bez);
Bitmap bmp = WebChartProdukt.Chart.Bitmap();
db.log.WriteDebug("Neue LabelPos: "+label.Left+"/"+label.Top);
And label.Left and label.Top is still zero.
Are you just guessing or do you know a solution to my problem?

Again I am angry, because I don't get proper support.
What's the matter?

Werner

Posted: Tue Nov 29, 2005 3:36 pm
by narcis
Hi Werner,

In the routine where do you implement the overlapping labels code you should treat labels as I did:

Code: Select all

         Bitmap bmp = WebChart1.Chart.Bitmap(); 
         for (int i=0;i<WebChart1.Chart.Axes.Left.Labels.Items.Count;++i) 
         { 
            Steema.TeeChart.AxisLabelItem Current = WebChart1.Chart.Axes.Left.Labels.Items[i]; 
//Do the overlapping check here
            Label1.Text=Label1.Text+" "+Current.Left.ToString()+"/"+Current.Top.ToString(); 
         } 
The code I pasted in my previous message works fine here using the latest TeeChart for .NET v2 release available at our customer download area.

Finally

Posted: Thu Dec 01, 2005 3:08 pm
by 9639216
I got a solution. Puuuh that was kind of hard.

I put the Bitmap bmp = WebChart1.Chart.Bitmap();
in the seperate function where I check for overlapping labels.

Now it works.
Mysterious that it did not work before, when I repainted it right after inserting it. Shoulda be kind of the same.

Anyway, it works now.
Thanks for giving me hints now and then.

Nice regards
Werner

Took a closer look at the solution

Posted: Thu Dec 01, 2005 3:35 pm
by 9639216
You have to call this

Code: Select all

Bitmap bmp = WebChart1.Chart.Bitmap();
to get WebChartProdukt_GetBottomAxisDrawLabel called before all labels are drawn.

And this did the trick to check for overlapping labels.

I hope this would be of any help to anybody.

Nice regards
Werner