find out X and Y pos of labels

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Werner
Newbie
Newbie
Posts: 29
Joined: Mon Nov 14, 2005 5:00 am

find out X and Y pos of labels

Post by Werner » Tue Nov 22, 2005 2:55 pm

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

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 23, 2005 12:20 pm

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;
		}
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
Newbie
Newbie
Posts: 29
Joined: Mon Nov 14, 2005 5:00 am

ASP.NET page

Post by Werner » Wed Nov 23, 2005 2:38 pm

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

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 Nov 24, 2005 2:33 pm

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=;
		}
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
Newbie
Newbie
Posts: 29
Joined: Mon Nov 14, 2005 5:00 am

Aha

Post by Werner » Thu Nov 24, 2005 2:42 pm

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

Werner
Newbie
Newbie
Posts: 29
Joined: Mon Nov 14, 2005 5:00 am

still zero

Post by Werner » Mon Nov 28, 2005 12:53 pm

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

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

Post by Narcís » Tue Nov 29, 2005 2:40 pm

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();
			}
		}
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
Newbie
Newbie
Posts: 29
Joined: Mon Nov 14, 2005 5:00 am

I am confused

Post by Werner » Tue Nov 29, 2005 3:26 pm

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

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

Post by Narcís » Tue Nov 29, 2005 3:36 pm

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.
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
Newbie
Newbie
Posts: 29
Joined: Mon Nov 14, 2005 5:00 am

Finally

Post by Werner » Thu Dec 01, 2005 3:08 pm

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

Werner
Newbie
Newbie
Posts: 29
Joined: Mon Nov 14, 2005 5:00 am

Took a closer look at the solution

Post by Werner » Thu Dec 01, 2005 3:35 pm

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

Post Reply