Legend question

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
madve
Newbie
Newbie
Posts: 13
Joined: Mon Dec 20, 2004 5:00 am

Legend question

Post by madve » Tue Oct 25, 2005 12:58 pm

Hello,

I'm sorry for disturbing you, this is not a bug report, just a question.

My problem:

I have a 2D Chart with Line serie. I have to mark the line when the values are over a specified limit with a different color line. I had an idea: I create a new Line serie when values are over the limit. OK. (Or have you got any other idea how to solve this problem?)

When the values are over the limit several times I have to create several series. OK.

But, when I show the Legend, it will show several Lines, but I just want to see only 2 Lines in legend: "Normal" and "Over the limit".

How can I filter the legend, not to show all series?

Best regards,

Gabor Varga

madve
Newbie
Newbie
Posts: 13
Joined: Mon Dec 20, 2004 5:00 am

Post by madve » Tue Oct 25, 2005 5:31 pm

Hello,

I found the solution of the second question:

tChart1.Series.ShowInLegend = false;



If you have another idea how to mark a line serie with another color if the value of the serie is over the limit, please tell me.

Best regards,

Gabor Varga

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 Oct 26, 2005 10:38 am

Hi Gabor,

Yes, you can easily do it this way:

Code: Select all

		private void Form1_Load(object sender, System.EventArgs e)
		{
			Random RandObj = new Random(100);

			for (int i=0;i<100;++i) line1.Add(RandObj.Next());

			for (int i=0;i<line1.Count;++i)
				if (line1.YValues.Value[i] < 1000000000) //put your threshold here
					line1[i].Color=Color.Red;
				else
					line1[i].Color=Color.Blue;
		}
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

madve
Newbie
Newbie
Posts: 13
Joined: Mon Dec 20, 2004 5:00 am

Post by madve » Wed Oct 26, 2005 1:29 pm

Hi,

Thanks for your quick response, it solved the coloring problem.

Is it possible to change other property of the line (like border width) without adding a new serie? (I think no, because these properties, like border width or style, seems me global for one serie).

Best regards,

Gabor

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 Oct 26, 2005 2:01 pm

Hi Gabor,

This is not possible directly on the line series. However you can get this custom drawing on tChart's canvas on the AfterDraw event doing something like this:

Code: Select all

		private void Form1_Load(object sender, System.EventArgs e)
		{ 			
			Random RandObj = new Random();
			
			for (int i=0;i<100;++i) line1.Add(RandObj.Next());

			for (int i=0;i<line1.Count;++i)
				if (line1.YValues.Value[i] < 1000000000) //put your threshold here
					line1[i].Color=Color.Red;
				else
					line1[i].Color=Color.Blue;		
		}

		private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
		{
			g.ClipRectangle(tChart1.Chart.ChartBounds);
			for (int i=1;i<line1.Count;++i)
			{   					
				tChart1.Graphics3D.Pen.Color=line1[i].Color;

				if (line1[i].Color.R>line1[i].Color.B) tChart1.Graphics3D.Pen.Width=5;
				else tChart1.Graphics3D.Pen.Width=2;

				tChart1.Graphics3D.Line(line1.CalcXPosValue(line1.XValues.Value[i-1]),
					line1.CalcYPosValue(line1.YValues.Value[i-1]),
					line1.CalcXPosValue(line1.XValues.Value[i]),
					line1.CalcYPosValue(line1.YValues.Value[i]));
			}
			g.UnClip();
		}
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

madve
Newbie
Newbie
Posts: 13
Joined: Mon Dec 20, 2004 5:00 am

Post by madve » Thu Oct 27, 2005 8:14 am

Hi Narcis,

Thank you very much for your quick response.

The solution will be the next:

I have 3 regions: Over Limit, Normal, Under limit like this:

Over Limit
------------------------ limit2
Normal
------------------------ limit1
Under limit

I will create 3 line series "Under limit", "Normal", "Over limit".
I will seperate the values into 3 groups: "Under limit", "Normal", "Over limit". (I have to add "special" values where the line cross the limit.)

I will set the color of the "Normal line" to Transparent when for example the values of "Normal" line is over the limit. (And do this when the values of "Over limit" line in "Normal" or "Under limit" region and so on...)

And now some ascii art... :wink:

e.g.: Normal line

"o" = value;
x = "special" values;
/ and \ lines
. = nothing (just to keep the distance beetween characters)

........o.........
......../\........ Over limit (line1.Color = Color.Transparent;)
-----x---x-----------------
..../........\....
...o.........o... Normal (line1.Color = Color.Green);
.../..........\...
-x----------x--------------------
./.............\... Under limit (line1.Color = Color.Transparent;)
o .............o..

Best regards,

Gabor Varga

Post Reply