04-08-2020 05:00 AM
In my application I use a WPF Graph showing data with a relative time format. The data shown on the X Axis is formattet like this.
public sealed class RelativeTimeFormatter : GeneralValueFormatter
{
public PrecisionDateTime? ZeroValue { get; set; }
protected override string FormatCore<TData>( TData value, ValuePresenterArgs args)
{
var time = value as PrecisionDateTime?;
if (!time.HasValue)
{
return base.FormatCore(value, args);
}
// Get the first time value specified for all waveforms
// or retrieve the last start value observed by the graph.
var zeroValue = ZeroValue ?? (PrecisionDateTime)args.Data["Zero Value"];
// Determine the time from Zero.
PrecisionTimeSpan difference = time.Value - zeroValue;
// Format result.
//string result = difference.ToString(Format ?? @"hh\:mm\:ss\.ffff");
string result = difference.ToString(Format ?? @"mm\:ss\.ffff");
return result;
}
}
I can use this for the range curser and also the single plot curser without any problems. I am creating the cursers in Code behind and not XAML.
ValueFormatterGroup myFormatterGroup = new ValueFormatterGroup();
myFormatterGroup.Separator = " ; "; // Seperator
myFormatterGroup.DefaultFormatter = new GeneralValueFormatter("0.00"); // Formatter Y-Axis
myFormatterGroup.ValueFormatters.Add(new RelativeTimeFormatter()); // Formatter X-Axis?
// Adding the formatter group to my curser and to the graph.
NationalInstruments.Controls.Cursor myCurser = new NationalInstruments.Controls.Cursor();
myCurser.ValuePresenter = myFormatterGroup;
graph1.Children.Add(myCurser);
I cant get it to work for the multi curser. I tried a few variations but i have no clue how i can format the Y-Values correctly. I tested it in a graph with two plots. The curser shows the X-Values correctly but the Y-Values also get formattet. I want to show them as double.
Right now it looks like this:
As you can see the values behind the ; are formattet very strangly.
I hope someone can help me with this.
Greetings
Marius
Solved! Go to Solution.
04-22-2020 03:59 PM
From the screenshot, it appears that the sample values are being formatted as date values?
Unfortunately, I could not reproduce the issue locally. It would be helpful to know what type of data your are sending to the graph. I have attached the test project I used, which supplies the graph with analog waveform data, and displays the samples numerically.
04-24-2020 02:14 AM
Thank you for taking the time. I am really sorry but I made a mistake while copy and pasting my source code. The normal curser works fine. The problem ist the multiplot cursor. Here is the code i used:
ValueFormatterGroup myFormatterGroup = new ValueFormatterGroup();
myFormatterGroup.Separator = " ; ";
myFormatterGroup.DefaultFormatter = new GeneralValueFormatter("0.00");
myFormatterGroup.ValueFormatters.Add(new RelativeTimeFormatter());
MultiPlotCursor myCurser = new MultiPlotCursor(); // <----- MultiPlotCursor
myCurser.ValuePresenter = myFormatterGroup;
graph1.Children.Add(myCurser);
I am using normal AnalogWaveforms<double>[]. The only thing that is custom and not implemented like in the doku examples is the custom time formatter.
X-Axis should be relative time while the Y-Axis just shows Double Values.
04-24-2020 10:54 AM
(Ah, wish I had caught that by adding more plot data in the first place!)
I updated my test project to use a multi-plot cursor and multiple plots (updated file attached). However, this displays correctly for me:
Perhaps you have a different version of Measurement Studio? I am using 2019.