Modifications to two color series

Mar 19, 2012 at 9:36 PM

Hi,

   The two color series is great, but I was wondering if it could be used exactly the same, but have the limit on the X axis instead of the Y axis (so it would be a vertical split instead of just horizontal split).

 

Also, it would be cool if it could have two limits.  So that below a min limit and above a max limit would be color2, but between the limits would be color1. 

 

Thanks!

Coordinator
Mar 20, 2012 at 6:22 PM

See the implementation of the TwoColorLineSeries, it is easy to create similar custom series that support vertical or multiple limits. The TwoColorLineSeries could also be extended to support all these cases!

Mar 20, 2012 at 9:02 PM

Cool, I'm working on it now and think I've got it.... except that I'm having a problem with using the axis.transform function on the datetime axis.  Even though I converted my "limit"  to a double using DateTimeAxis.ToDouble from a datetime, I'm having problems getting the screen coordinates for the position I want.  Any thoughts?

Mar 22, 2012 at 3:27 PM

I was able to find a way to get this to work on a datetime axis.  I created a vertical annotation and bound the limit of the custom two color series to the X property of the annotation.  That worked fine.  If you want to add a 2 color vertical line series that uses a max and min limit, this is the code I used.  Feel free to clean it up and add it to oxyplot if you think it would help. I only tested this for wpf, but it worked perfectly.  First I created copies TwoColorLineSeries.cs in oxyplot/series and TwoColorLineSeries in oxyplot.wpf/series in their respective folders and called them both TwoColorVerticalLineSeries.  After updating the files to allow for a MinLimit and MaxLimit and changing the names when needed, the only important code that was any different came from the .cs in the main oxyplot TwoColorVerticalLineSeries with the RenderSmoothefLine function.  This is the code I used in place of what was in there.  I don't think it will work for a reversed X axis, and might need an error check on the max/min limit, but here it is:

 

protected override void RenderSmoothedLine(IRenderContext rc, OxyRect clippingRect, IList<ScreenPoint> pointsToRender)
{
     double right = clippingRect.Right;
     double minX = this.XAxis.Transform(this.MinLimit);
     double maxX = this.XAxis.Transform(this.MaxLimit);
         
     if (minX < clippingRect.Left) minX = clippingRect.Left;
     if (minX > right) minX = right;
     if (maxX < clippingRect.Left) maxX = clippingRect.Left;
     if (maxX > right) maxX = right;
     if (maxX < minX) maxX = minX;
                     
     clippingRect.Right = minX;
     rc.DrawClippedLine(
          pointsToRender, 
          clippingRect, 
          this.MinimumSegmentLength * this.MinimumSegmentLength, 
          this.Color2, 
          this.StrokeThickness, 
          this.LineStyle2, 
          this.LineJoin, 
          false);
         
     clippingRect.Left = minX;
     clippingRect.Width = maxX - minX;
     rc.DrawClippedLine(
          pointsToRender, 
          clippingRect, 
          this.MinimumSegmentLength * this.MinimumSegmentLength, 
          this.Color, 
          this.StrokeThickness, 
          this.LineStyle, 
          this.LineJoin, 
          false);

     clippingRect.Left = maxX;
     clippingRect.Width = right - maxX;
     rc.DrawClippedLine(
          pointsToRender,
          clippingRect,
          this.MinimumSegmentLength * this.MinimumSegmentLength,
          this.Color2,
          this.StrokeThickness,
          this.LineStyle2,
          this.LineJoin,
          false);
}

 

Coordinator
Mar 30, 2012 at 12:38 PM

thanks, I will try to create a "LimitedLineSeries" later :) see http://oxyplot.codeplex.com/workitem/9951