2

I have an OHLC stock price chart in Zedgraph. I would like to add multiple line segments on this graph where I only know the start and end point values - so basically, I have a (start date, price) and an (end date, price) combination of 2 points which I want to draw a line through.

enter image description here

I tried using the following code but this adds all the lines to the beginning of the graph, irrespective of the x-axis value that I provide.

LineItem trendLine = new LineItem(String.Empty, new[] { pstartDate, pconfirmDate },   new[] { pstartPrice, pconfirmPrice }, System.Drawing.Color.Black, SymbolType.None);
trendLine.Line.Style = System.Drawing.Drawing2D.DashStyle.Solid;
trendLine.Line.Width = 1f;
pricePane.CurveList.Add(trendLine);

Thanks in advance.

NEW OBSERVATIONS - My OHLC graph currently has scrolling and zoom across X-axis enabled. I am using the X-Axis Type 'DateAsOrdinal'. I observed that if I change my X-Axis type to 'Date', the line segments appear as they should, i.e., in the correct place along the X-Axis. But now the scroll has become disabled and the data that was originally being displayed is only partially displayed now!

sinhars82
  • 124
  • 1
  • 1
  • 8
  • I think I figured out a crude way to solve this problem. The DateAsOrdinal axis type cannot have missing points in the line item I want to add. So I had to add 'empty' points with Y-value double.NAN for all the points that are not inside the line segment. – sinhars82 Apr 22 '14 at 21:27

1 Answers1

0

For a trend line you should rather use LineObj.

If your XAxis is DateAsOrdinal, the x values must be ordinal, not dates.

bretddog
  • 5,411
  • 11
  • 63
  • 111
  • Hi Bretddog, please can you elaborate what is the difference between a LineItem and LineObj? Also, when you say that x values must be ordinal, can there be missing x values at the beginning or end? – sinhars82 Apr 27 '14 at 14:47
  • LineItem:CurveItem is a continuous plot. LineObj:GraphObj only has two data points, then obviously no values to miss. Typically then a trend line would be easier to handle as a LineObj. But know the two, and use what is convenient. – bretddog Apr 27 '14 at 19:28