
LineAnnotation, top axis and other plot interaction
PythagDev wrote at 2012-09-05 16:48:
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.
PythagDev wrote at 2012-09-05 16:59:
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.
objo wrote at 2012-09-05 19:25:
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?
PythagDev wrote at 2012-09-05 21:17:
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.
objo wrote at 2012-09-05 23:12:
try creating a new instance of the LineAnnotation for each PlotModel.
PythagDev wrote at 2012-09-06 03:43:
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.
PythagDev wrote at 2012-09-06 03:50:
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!
Customer support service by UserEcho