Page 1 of 1

Legend.Width

Posted: Tue May 27, 2008 2:12 pm
by 9338755
Hi,

I want my legend to be of a fixed size so I set AutoSize to false. But always when I try to set the Width property it resets itself back to its old value. What am I doing wrong?

Posted: Tue May 27, 2008 2:59 pm
by narcis
Hi ctusch,

Could you please send us a simple example project we can run "as-is" to reproduce the problem here?

You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.

Posted: Wed May 28, 2008 10:00 am
by 9338755
Hi Narcis,

I wasn't able to reproduce my exact problem inside a demo app but another problem appeared there (I've uploaded the project): When I set Legend.AutoSize to false the legend won't display at all. I don't know if these two problems are related.

Posted: Wed May 28, 2008 10:35 am
by narcis
Hi ctusch,

Thanks for the example project. I could reproduce the issue here and it's probable they are related. I've added the bug (TF02013088) to our defect lst to be fixed for next releases. In the meantime you can set custom legend position:

Code: Select all

        public Form1()
        {
            InitializeComponent();

            Line line = new Line();

            this.tChart1.Series.Add(line);
            line.Add(1, 0);
            line.Add(2, 2);
            line.Add(3, 3);
            line.Add(4, 3);

						tChart1.Legend.AutoSize = false;

						tChart1.Panel.MarginRight = 20;
						tChart1.Legend.CustomPosition = true;
						Bitmap bmp = tChart1.Bitmap;
						Rectangle rect = tChart1.Chart.ChartRect;
						tChart1.Legend.Left = rect.Right + 10;
						tChart1.Legend.Top = rect.Top;
        }

Posted: Wed May 28, 2008 11:27 am
by 9338755
Alright, thanks!

Posted: Wed May 28, 2008 12:26 pm
by 9338755
Narcis,

now I seem to experience the same problem as before. I changed the code of the sample project as you posted but I get bad results. I've uploaded you two screen shots, one after program startup and the other after rescaling the window. Aren't you experiencing the same problems?

Posted: Wed May 28, 2008 12:41 pm
by narcis
Hi ctusch,

Yes, in that case you'll need to use AfterDraw and Resize events like this:

Code: Select all

        public Form1()
        {
            InitializeComponent();

            Line line = new Line();

            this.tChart1.Series.Add(line);
            line.Add(1, 0);
            line.Add(2, 2);
            line.Add(3, 3);
            line.Add(4, 3);

						tChart1.Legend.AutoSize = false;

						tChart1.Panel.MarginRight = 20;
						tChart1.Legend.CustomPosition = true;
						Bitmap bmp = tChart1.Bitmap;						
        }

				private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
				{
					Rectangle rect = tChart1.Chart.ChartRect;
					tChart1.Legend.Left = rect.Right + 10;
					tChart1.Legend.Top = rect.Top;
				}

				private void tChart1_Resize(object sender, EventArgs e)
				{
					Bitmap bmp = tChart1.Bitmap;
				}

Posted: Wed May 28, 2008 1:40 pm
by 9338755
Narcis,

I was able to set the Legend.Width after calling tChart1.Bitmap. Now I'm still having the problem that the legend doesn't keep itself at a fixed distance from the right border. I've uploaded two screen shots for you again.

Posted: Wed May 28, 2008 2:45 pm
by narcis
Hi ctusch,

In that case you can implement AfterDraw event like this:

Code: Select all

				private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
				{
					Rectangle rect = tChart1.Chart.ChartRect;
					//tChart1.Legend.Left = tChart1.Width - 100;
					tChart1.Legend.Left = tChart1.Width - tChart1.Legend.Width;
					tChart1.Legend.Top = rect.Top;
				}

Posted: Thu May 29, 2008 8:37 am
by narcis
Hi ctusch,

As an update, a TeeChart for .NET developers pointed me out that he doesn't think TF02013088 is a bug. When you set AutoSize to false, you have to set the width and height manually. The following code works as expected:

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}
				
		private void InitializeChart()
		{
			Steema.TeeChart.Styles.Line line = new Steema.TeeChart.Styles.Line();

			this.tChart1.Series.Add(line);
			line.Add(1, 0);
			line.Add(2, 2);
			line.Add(3, 3);
			line.Add(4, 3);

			tChart1.Legend.Width = 50;
			tChart1.Legend.Height = 100;
			tChart1.Legend.AutoSize = false;
		}

Posted: Thu May 29, 2008 8:39 am
by narcis
Hi ctusch,

As an update, a TeeChart for .NET developers pointed me out that he doesn't think TF02013088 is a bug. When you set AutoSize to false, you have to set the width and height manually. The following code works as expected:

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}
				
		private void InitializeChart()
		{
			Steema.TeeChart.Styles.Line line = new Steema.TeeChart.Styles.Line();

			this.tChart1.Series.Add(line);
			line.Add(1, 0);
			line.Add(2, 2);
			line.Add(3, 3);
			line.Add(4, 3);

			tChart1.Legend.Width = 50;
			tChart1.Legend.Height = 100;
			tChart1.Legend.AutoSize = false;
		}