04-15-2013 09:31 AM
Hello,
I'm trying to plot a secondary y-axis on my WPF graph. I have a graph bound to an array of AnalogWaveform<double> objects which I change at runtime. This array can be different sizes depending on user selection, however assume that there are two types of data to graph.
I would like to correspond one type of data to my primary y-axis and the other type to my secondary y-axis. For example, I could have four AnalogWaveform<double> objects to plot, two of which are in Hz (primary) and the other two in Volts (secondary).
According to the documentation, I need an extra <axis> element under my <Graph.Axes> definition. What I have is therefore:
<ni:Graph ...> <ni:Graph.Axes> <ni:AxisDouble x:Name="_yAxis" Orientation="Vertical" MinorDivisions="{x:Null}"> <ni:AxisDouble.LabelTemplate> <DataTemplate> <Label Margin="5" Content="{Binding}"/> </DataTemplate> </ni:AxisDouble.LabelTemplate> <ni:AxisDouble.MajorDivisions> <ni:RangeLabeledDivisions Mode="Count: 11" TickVisibility="Hidden"/> </ni:AxisDouble.MajorDivisions> <ni:AxisDouble.MajorGridLines> <ni:GridLines Stroke="#FFD8D8D8" StrokeThickness="2"/> </ni:AxisDouble.MajorGridLines> </ni:AxisDouble> <ni:AxisDouble x:Name="_ySecondaryAxis" Orientation="Vertical" MinorDivisions="{x:Null}"> <ni:AxisDouble.MajorDivisions> <ni:RangeLabeledDivisions Mode="Count: 11" TickVisibility="Hidden"/> </ni:AxisDouble.MajorDivisions> </ni:AxisDouble> <ni:AxisPrecisionDateTime x:Name="_xAxis" Orientation="Horizontal" Label="Time"> </ni:AxisPrecisionDateTime> </ni:Graph.Axes> <ni:Graph.Children> <ni:MultiPlotCursor Name="_mpCursor" Visibility="Hidden"/> </ni:Graph.Children> </ni:Graph>
This adds a second y-axis to the left of my primary y-axis. What I need is for this axis to be located to the right of my graph, and somehow to plot each AnalogWaveform<double> on the correct y-axis.
I build my plots in code as follows:
_graph.Plots.Clear();
// RawData is my AnalogWaveform<double>[], built beforehand based on a server response foreach (AnalogWaveform<double> waveform in RawData) { if (waveform != null) { plot = new Plot(waveform.ChannelName); plot.DataContext = waveform; plots.Add(plot); //plots is a simple List<plot> } } _graph.Plots.AddRange(plots); //add plots to graph _legend.ItemsSource = plots; //add plots to legend
Any help would be appreciated on how to do this.
Thanks in advance.
Solved! Go to Solution.
04-15-2013 01:28 PM
To position your second Y axis on the other side of the graph, set the Location
property on the axis to Far
.
To associate a plot with a non-default Y axis, set the VerticalScale
property on the plot to the appropriate Y axis value.
04-16-2013 07:29 AM
Thanks Paul, that works.