LineAnnotation, top axis and other plot interaction

Sep 5, 2012 at 2:48 PM

Short version: Vertical LineAnnotation doesn't go all the way across the plot.

Long version: I'm using multiple PlotModels in a vertical stackpanel (WPF) to show a number of signals.  The top PlotModel has a top and bottom horizontal axis.  The remaining PlotModels only have a bottom axis. The top axis is time.  The bottom axes on all the graphs are a time index value that the data is referenced to, but is meaningless to the user.  Occasionally there are breaks in the time.  I wanted to show that by a vertical line where there was a time break.  I used a LineAnnotation to do that and it mostly works.  However, on the top plot the line starts at the top of the top axis and goes a little ways down into the plot area of the graph then stops, but ONLY if there is another PlotModel on the stackpanel that uses a vertical CategoryAxis (used for discrete signals).  If there are only analog signals (using a vertical LinearAxis), the line goes all the way down the plot like the rest of the graphs.  I've stepped through the LineAnnotation:Render code and it seems to form the points and clip correctly.  I'd appreciate any help in determining why this is doing this!

Thanks.

Sep 5, 2012 at 2:59 PM

Actually, if there are only PlotModels that use LinearAxis for their vertical axis, the top PlotModel LineAnnotation still stops a little short of the bottom horizontal axis, but it gets a lot closer.

Coordinator
Sep 5, 2012 at 5:25 PM

Are you creating the plots by XAML, or do you bind PlotModels to the Model property? Are you using DataTemplates? Could it be related to http://oxyplot.codeplex.com/workitem/10000?

Can you send an image how it looks? Or generated code (Ctrl+Alt+C) to reproduce the error?

Sep 5, 2012 at 7:17 PM

Thanks for the quick response.  I do this programmatically, not in XAML and don't use data templates.  I bind the plot model to the model properties:

foreach (PlotModel lPlotModel in graphData.PlotModels) 
{
    OxyPlot.Wpf.Plot lPlot = new Plot(); 
    lPlot.Model = lPlotModel;
    if (lPlotIndex == 0) { 
      // add extra space on first graph for top time axis
      lPlot.Height = graphData.PlotHeights[lPlotIndex] + 30; 
    } 
    else {
       lPlot.Height = graphData.PlotHeights[lPlotIndex]; 
    } 
    lPlot.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; 
    lPlot.Margin = new Thickness(0, 0, 2, 0); 
// snipped out putting filter on axes to limit data range shown 
    // MainGraphDisplay is the stackpanel 
    MainGraphDisplay.Children.Add(lPlot);
    lPlotIndex++; 
} 
The code to create the line annotation looks like:
foreach (int lTimeBreak in lTimeBreaks)
{
    LineAnnotation lVertBar = new LineAnnotation();
    lVertBar.LineStyle = LineStyle.Solid;
    lVertBar.Color = OxyColor.FromRGB(255, 0, 0);
    lVertBar.Type = LineAnnotationType.Vertical;
    lVertBar.X = lTimeBreak;
    lVertBar.Layer = AnnotationLayer.AboveSeries;
    lVertBar.ClipByXAxis = false;

    foreach (PlotModel lPlotModel in PlotModels)
    {
        lPlotModel.Annotations.Add(lVertBar);
    }
}

I'd love to attach a screenshot but haven't figured out how to.
Coordinator
Sep 5, 2012 at 9:12 PM

try creating a new instance of the LineAnnotation for each PlotModel.

Sep 6, 2012 at 1:43 AM

Good tip. I should have thought of that!

Rob

From: objo [email removed]
Sent: Wednesday, September 05, 2012 4:13 PM
To: rcoker@pythagdev.com
Subject: Re: LineAnnotation, top axis and other plot interaction [oxyplot:394496]

From: objo

try creating a new instance of the LineAnnotation for each PlotModel.

Sep 6, 2012 at 1:50 AM
Edited Sep 6, 2012 at 1:50 AM

That did fix the problem.  It makes sense because the discrete signal plots were much shorter, so when the endpoints were determined it was a short line - the short line was being reused in the top graph since it was after all the same object.

Thanks a ton!