Page 1 of 1

Problem in drawing legend

Posted: Thu Jul 31, 2008 11:07 am
by 14047415
Hi,

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

Problem is explained there only.

-Raed

Posted: Thu Jul 31, 2008 11:27 am
by narcis
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!

Posted: Fri Aug 08, 2008 9:11 am
by 14047415
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

Posted: Mon Aug 11, 2008 7:25 am
by 14047415
Hi,

Please reply for a previous mail.

Thanks,
Sanyog

Posted: Mon Aug 11, 2008 2:35 pm
by Chris
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.

Posted: Wed Aug 13, 2008 7:35 am
by 14047415
Hi,

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

Thanks
Sanyog

Posted: Wed Aug 13, 2008 8:43 am
by Chris
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.

Posted: Wed Aug 13, 2008 9:07 am
by 14047415
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

Posted: Wed Aug 13, 2008 9:26 am
by Chris
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.