Problem in drawing legend

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
drillright40
Newbie
Newbie
Posts: 57
Joined: Mon Nov 19, 2007 12:00 am

Problem in drawing legend

Post by drillright40 » Thu Jul 31, 2008 11:07 am

Hi,

I have uploaded one file named "3DPlotLegend.bmp".

Problem is explained there only.

-Raed

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 Jul 31, 2008 11:27 am

Hi Raed,

You can do something as in the What's New?\Welcome !\New in Legend\Legend Items example in the features demo, available at TeeChart's program group.

You could combine with legend's click events for dynamically creating a TextBox for the legend item you want to edit, for example:

Code: Select all

		private int index = -1;
		private TextBox text1;

		void tChart1_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			int index = tChart1.Legend.Clicked(e.X, e.Y);

			if (index!=-1)
			{
				text1 = new TextBox();
				tChart1.Controls.Add(text1);
				text1.Location = new System.Drawing.Point(e.X, e.Y);
				text1.Name = "text1";
				text1.Size = new System.Drawing.Size(100, 20);
				text1.TextChanged += new EventHandler(text1_TextChanged);
			}
		}
Hope this helps!
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

drillright40
Newbie
Newbie
Posts: 57
Joined: Mon Nov 19, 2007 12:00 am

Post by drillright40 » Fri Aug 08, 2008 9:11 am

Hi,
I have only one suface added in my code. For showing all the labels on the legend, what exactly I have to do?

If you see the uploded image file. The legend is having so many things like flag symbols, edit box.

I am unable to get the clear picture by your solution. It needs more information.

Thanks,
Sanyog

drillright40
Newbie
Newbie
Posts: 57
Joined: Mon Nov 19, 2007 12:00 am

Post by drillright40 » Mon Aug 11, 2008 7:25 am

Hi,

Please reply for a previous mail.

Thanks,
Sanyog

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Mon Aug 11, 2008 2:35 pm

Hello,
drillright40 wrote:Please reply for a previous mail.
To add custom symbols to a Legend, see the Features demo under:
All Features\Welcome !\Miscellaneous\Legend\OnDrawSymbol Event

To change the text of an existing legend item, see the Features demo under:
What's New?\Welcome !\New in Legend\Legend Items

Narcís' code shows you how to add edit boxes to a legend to change its text.
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

drillright40
Newbie
Newbie
Posts: 57
Joined: Mon Nov 19, 2007 12:00 am

Post by drillright40 » Wed Aug 13, 2008 7:35 am

Hi,

Cann't we create a custom legend? If yes, how?

Thanks
Sanyog

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Wed Aug 13, 2008 8:43 am

Hello,
drillright40 wrote:Cann't we create a custom legend? If yes, how?
Of course you can. You could start with something like this:

Code: Select all

	public partial class Form3 : Form
	{
		public Form3()
		{
			InitializeComponent();
			InitializeChart();
		}		

		private TChart tChart1;
		private MyLegend myLegend;

		private void InitializeChart()
		{
			tChart1 = new TChart();
			tChart1.Dock = DockStyle.Fill;
			this.Controls.Add(tChart1);

			myLegend = new MyLegend(tChart1.Chart);

			tChart1.AfterDraw+=new PaintChartEventHandler(tChart1_AfterDraw);

			tChart1.Series.Add(typeof(Line));
			tChart1[0].FillSampleValues();
			tChart1.Legend.Visible = false;
			tChart1.Panel.MarginRight = 40;
		}

		void tChart1_AfterDraw(object sender, Graphics3D g)
		{
			myLegend.Draw(g, Utils.FromLTRB(tChart1.Width - 200, 100, tChart1.Width - 50, 250));
		}
	}

	public class MyLegend : TeeBase
	{
		public MyLegend() : this((Chart)null) { }
		public MyLegend(Chart c) : base(c) { }

		public void Draw(Graphics3D g, Rectangle r)
		{
			g.Pen.Color = Color.Green;
			g.Brush.Color = Color.Red;
			g.Rectangle(r);
			g.Font.Bold = true;
			g.TextOut(r.X, r.Y, base.Chart[0].Title);
		}
	}
Of course, you don't have to inherit from TeeBase. You could use reflector to study teechart's Legend class and use that as inspiration.
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

drillright40
Newbie
Newbie
Posts: 57
Joined: Mon Nov 19, 2007 12:00 am

Post by drillright40 » Wed Aug 13, 2008 9:07 am

Hi,

Not this way.

Basically I want to create a new legend. Add items to the chart legend.

tchart.Legend.Items.Add()

and then assign newly created legend to the chart legend.

You already knew my problem related to legend.

Can you suggest me the approach or solution?

Thanks,
Sanyog

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Wed Aug 13, 2008 9:26 am

Hello,
drillright40 wrote: Can you suggest me the approach or solution?
I have already pointed to you several examples in the feature demo which having seen images of what you are trying to achieve, I thought were relevant. What is more, I've just shown you how you can draw your own legend with with whatever you want in it.

Short of actually writing your code for you, I can't think of what more I can do to help you.
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Post Reply