Page 1 of 1

Customized Legend

Posted: Wed Mar 16, 2005 12:50 pm
by 8119814
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

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

Posted: Wed Mar 16, 2005 12:58 pm
by 8119814
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

Posted: Wed Mar 16, 2005 1:06 pm
by 8886281
It works now, but I don't know why. Strange!

Posted: Wed Mar 16, 2005 1:14 pm
by narcis
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.

Posted: Wed Mar 16, 2005 1:57 pm
by 8886281
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?

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

Posted: Mon Mar 21, 2005 9:08 am
by 8886281
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?

Posted: Mon Mar 21, 2005 4:09 pm
by narcis
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.