Page 1 of 1

DrawLine tool works strange

Posted: Fri May 04, 2007 9:59 am
by 9640311
For building financial type charts we use custom vertical axes to have both left and right axes and place one chart under another. Everything works as expected.

Our application requires an ability to place a custom line on chart. To accomplish that we use DrawLine tool and the following code:

Code: Select all

DrawLine drawLine = new DrawLine(TeeChart.Chart);
drawLine.EnableDraw = false;
DrawLineItem item = new DrawLineItem(drawLine);
double startX = TeeChart.Axes.Bottom.Minimum + 10;
double startY = TeeChart.Axes.Left.Minimum + 10;
double endX = TeeChart.Axes.Bottom.Maximum - 10;
double endY = TeeChart.Axes.Left.Maximum - 10;
item.StartPos.X = startX;
item.StartPos.Y = startY;
item.EndPos.X = endX;
item.EndPos.Y = endY;

drawLine.Invalidate();
As a result sometimes line does not show up at all, sometimes it shows up but does not allow to resize.

Sometimes lines are now shown, but when chart is saved and opened from file lines are shown.

Please advise.

Posted: Fri May 04, 2007 10:24 am
by narcis
Hi stratadat,

The line may not be drawn because your chart hasn't been painted yet and thus axes minimum and maximum properties don't have valid values yet.

It works fine for me here using the code below. You'll notice that before drawing the line I make a Bitmap call to force the chart being internally painted and make properties having valid values.

Code: Select all

		private void Form1_Load(object sender, EventArgs e)
		{
			candle1.FillSampleValues();

			Steema.TeeChart.Tools.DrawLine drawLine = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);
			drawLine.EnableDraw = false;
			Steema.TeeChart.Tools.DrawLineItem item = new Steema.TeeChart.Tools.DrawLineItem(drawLine);

			Bitmap bmp = tChart1.Bitmap;

			double startX = tChart1.Axes.Bottom.Minimum + 10;
			double startY = tChart1.Axes.Left.Minimum + 10;
			double endX = tChart1.Axes.Bottom.Maximum - 10;
			double endY = tChart1.Axes.Left.Maximum - 10;
			item.StartPos.X = startX;
			item.StartPos.Y = startY;
			item.EndPos.X = endX;
			item.EndPos.Y = endY;

			drawLine.Invalidate(); 
		}

Posted: Fri May 04, 2007 11:36 am
by 9640311
Sorry, you code does not work for me as well. We have found strange thing while debugging - when line is not displayed the values of StartHandle and EndHandle properties of DrawLineItem is System.NullReferenceException

Posted: Fri May 04, 2007 11:38 am
by narcis
Hi stratadat,

Could you please send us a simple example project we can run "as-is" to reproduce your 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.