Customized Legend

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Glenn F. Henriksen
Newbie
Newbie
Posts: 52
Joined: Tue Mar 04, 2003 5:00 am

Customized Legend

Post by Glenn F. Henriksen » Wed Mar 16, 2005 12:50 pm

Hi,

I am displaying a line chart that is separated into multiple regions, this is done by setting the "ColorEach" property to true and applying different colors to the chart points. Now, I would like to display a legend containing the names and colors of the regions.

I am already aware of the "GetLegendText" event, but how to set the number of legend items?

Thanks in advance,
Holger Persch

Glenn F. Henriksen
Newbie
Newbie
Posts: 52
Joined: Tue Mar 04, 2003 5:00 am

Ups, wrong forum user name??????

Post by Glenn F. Henriksen » Wed Mar 16, 2005 12:58 pm

I have logged in using my license number and password, but I am not "Annelise". Seems to be something has been messed up with the license numbers.

How to correct this?

Regards,
Holger Persch

Holger Persch
Newbie
Newbie
Posts: 6
Joined: Mon Mar 14, 2005 5:00 am
Location: Germany

Post by Holger Persch » Wed Mar 16, 2005 1:06 pm

It works now, but I don't know why. Strange!
Regards
Holger Persch

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 Mar 16, 2005 1:14 pm

Hi Holger,

I don't know exactly what you mean with "Legend Items" but you can do something like the code below. You can add a label to each point when populating series, also defining a color for each point and finally define a textstyle for the legend.

Code: Select all

		private void Form1_Load(object sender, System.EventArgs e)
		{
			int i;

			line1.Marks.Visible=true;
			for (i=0;i<10;++i)
				line1.Add(i,"point "+i.ToString(),System.Drawing.Color.Blue);

			tChart1.Legend.TextStyle = Steema.TeeChart.LegendTextStyles.Plain;
		}

		private void tChart1_GetLegendText(object sender, Steema.TeeChart.GetLegendTextEventArgs e)
		{
			e.Text = line1.YValues[e.Index] + ", " + e.Text;
		}
If it doesn't fit your needs please specify what you exactly need.
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

Holger Persch
Newbie
Newbie
Posts: 6
Joined: Mon Mar 14, 2005 5:00 am
Location: Germany

Post by Holger Persch » Wed Mar 16, 2005 1:57 pm

Hi Narcis,

Thanks for the help, but unfortunately it doesn't fit my needs. I have create a sample, please try the following code:

Code: Select all

		private void Form1_Load(object sender, System.EventArgs e)
		{
			this.tChart1.Aspect.View3D = true;

			this.line1 = this.tChart1.Series.Add(new Steema.TeeChart.Styles.Line()) as Steema.TeeChart.Styles.Line;
			this.line1.Marks.Visible = false;

			for (int i = 0; i < 96; i++)
			{
				this.line1.Add(i, 100, i.ToString(), i <= 24 ? Color.Green : i <= 72 ? Color.Red : Color.Green);
			}
		}
You will see a line chart separated into three regions, the first one is colored green, the second one is red and the third one is green again.

Now I want the legend to display two entries like:
[Green] "NT"
[Red] "HT"

How to achieve this?
Regards
Holger Persch

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 Mar 16, 2005 3:41 pm

Hi Holger,
It works now, but I don't know why. Strange!
This must be because you were using the evaluation version license or something similar. We will have to look into this.

Regarding your legend customization you have several alternatives:

Code: Select all

		private void Form1_Load(object sender, System.EventArgs e)
		{			this.tChart1.Aspect.View3D = true; 

			Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
			line1.Marks.Visible = false; 

			for (int i = 0; i < 96; i++) 
			{ 
				line1.Add(i, 100, i.ToString(), i <= 24 ? Color.Green : i <= 72 ? Color.Red : Color.Green);
			} 

			this.tChart1.Axes.Bottom.Labels.Style = Steema.TeeChart.AxisLabelStyle.Value;
			this.tChart1.Legend.FirstValue = 94;
			line1[94].Color = Color.Green;
			line1[94].Label = "NT";
			line1[95].Color = Color.Red;
			line1[95].Label = "HT";  
		
private void tChart1_GetLegendText(object sender, Steema.TeeChart.GetLegendTextEventArgs e)
		{
			e.Text = e.Text.Replace("100", "");
		}
If you don't want the last value being red you may create a "stunt" value not displayed in the series.

Another solution could be something like:

Code: Select all

		private void Form1_Load(object sender, System.EventArgs e)
		{
			this.tChart1.Aspect.View3D = true; 
			
			Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
			Steema.TeeChart.Styles.Line line2 = new Steema.TeeChart.Styles.Line(tChart1.Chart);

			line1.Marks.Visible = false; 
			line2.Marks.Visible = false;

			for (int i = 0; i < 96; i++) 
			{
				if ((i  < = 24 || (i (greater than char) 72))
					line1.Add(i, 100, i.ToString(), Color.Green);
				else 
				{
					line1.Add();
					line2.Add(i, 100, i.ToString(), Color.Red);
				}
			}

			line2.ZOrder=line1.ZOrder;			

			line1.Title = "NT";
			line2.Title = "HT";			    
		}

		private void tChart1_GetLegendText(object sender, Steema.TeeChart.GetLegendTextEventArgs e)
		{
			e.Text = e.Text.Replace("100", "");
		}
Please note that I had to use the "(greather than char)" instead "<" due to a forums parsing problem
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

Holger Persch
Newbie
Newbie
Posts: 6
Joined: Mon Mar 14, 2005 5:00 am
Location: Germany

Post by Holger Persch » Mon Mar 21, 2005 9:08 am

Hi Narcís,

Thanks for your help, this gave me an idea how to solve it.

Are there any plans for implementing a customizable legend (like Dundas Chart has) into TeeChart.Net. This could be look like:

Code: Select all

this.TChart1.Legend.LegendStyle = LegendStyles.Custom;
this.TChart1.Legend.SetItem(0, "HT", Color.Red);
this.TChart1.Legend.SetItem(1, "NT", Color.Green);
I had a look into the TeeChart sources and I think the effort is acceptable. Mybe I will try to implement it for test purposes.

What do think about that?
Regards
Holger Persch

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 Mar 21, 2005 4:09 pm

Hi Holger,

I have already added your request to our wish-list to be considered for future releases.

In this specific case you may also like to send us the customizations you implement.
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

Post Reply