02-15-2016 08:31 AM
Hi,
I use WPF graph from MS2015. I want to add plots to the graph programatically, the x axis ahould be synchronized for all plots but the y axis is different (according to the plot scale).
I attached an example.
Solved! Go to Solution.
02-15-2016 01:08 PM
The graph does not support a configuration option for the kind of scale stacking shown in your image (you can show scales on different sides of a graph using Location
, but you can't show two different vertical scales in the same "column" on one side of a graph). To achieve that exact effect, you can use multiple graphs instead of multiple plots, with a binding between the Range
of each horizontal axis.
If your vertical ranges have the same magnitude, then that is all you would need to do. If your vertical ranges differ significantly though, the plot area of each graph would not align without some additional work to adjust the margin.
02-17-2016 07:05 AM
I'm trying to do that with multiple graphs.
I want that only the x axis of the graph in the bottom will be visible. I tried this code in the seconf graph to try hiding the lables, but I till see lables of some divisions in the second graph:
<ni:Graph.Axes>
<chart:CustomXAxis x:Name="Graph1XScale" Orientation="Horizontal" Adjuster="FitVisibleExactly" >
<chart:CustomXAxis.MajorDivisions>
<ni:RangeLabeledDivisions LabelPresenter=""/>
</chart:CustomXAxis.MajorDivisions>
I attached a print screen.
Thanks.
02-17-2016 09:35 AM
No need to hide the individual elements; just set the Visibility
of your custom X axis to Collapsed
.
02-18-2016 07:42 AM
02-22-2016 06:09 AM
I'm trying to implement RangeCursor that will apear only in the graph in the bottom but will RetrieveValues of plots from the other graphs.
There is an exception if I try to do RetrieveValues of plot not from the parent graph.
I guess I need to add RangeCursor also for the rest of the graphs and set it to be invisible, and do RetrieveValues for each RangeCursor . Is there a way to bind the range of RangeCursor to other RangeCursor ?
02-22-2016 11:08 AM
First, to answer your binding question, you can bind the HorizontalRange
of your hidden cursors to the ActualHorizontalRange
of the main cursor.
However, RetrieveValues
is just a convenience method for the FindValues
method on the graph. Since you have the horizontal ranges aligned, you can call otherGraph.FindValues( otherPlot, cursor.ActualHorizontalRange, null, true )
to get the values in the other graphs.
02-23-2016 04:55 AM
The otherGraph.FindValues( otherPlot, cursor.ActualHorizontalRange, null, true ) sounds like a better solution, thanks for the advice.
It works for me except one thing.
In case that the DataSource of the graphs being updated (appending new sampels to the collection) the other graphs that the Range of their x axis is binded to the Range of the main graph x axis return array with no y values (only x values returned) when calling to otherGraph.FindValues .
If I pause the appending of sampels it works fine.
It make sense that user will pause the sampeling when playing with the RangeCursor but if he didn't do that he won't understand what is going on.
02-23-2016 01:49 PM
Based just on your description, it's not clear to me what order data updates/synchronization/queries are taking place. If you could share an example that reproduces the issue, it would be easier to determine where the problem is occuring.
02-24-2016 06:20 AM
I have one RangeCursor that is child of the main graph.
I subscribe:
rangeCursor.PositionChanged += rangeCursor_PositionChanged
Inside the handler I call to:
public static void SendPlotsData(RangeCursor rangeCursor, Graph[] graphs)
{
...
...
foreach (var graph in graphs.Where(graph => graph != null))
{
for (int i = 0; i < graph.AllPlots.Count; i++)
{
var values = graph.FindValues(graph.AllPlots[i], rangeCursor.ActualHorizontalRange, null, true);
if (values.Count < 2)
{
return;
}
var yValues = (Buffer<double>)values[1];
...
...
The DataSource of the graphs updated every second with new samples.
If I show the RangeCursor and the DataSource being updated (appending new sampels to the ChartCollectionAnalogWaveform) so the handler rangeCursor_PositionChanged is being called (even that I didn't move the cursor).
In this case the graph.FindValues of otherr graphs return only x values.
The problem occures when the handler rangeCursor_PositionChanged is raised due to DataSource update, If I move the cursors with the mouse (and so trigger rangeCursor_PositionChanged) it works ok.