10-25-2017 09:55 AM
Suppose I have two arrays of doubles to plot, plot1 has 1000 samples with sampling rate at 1KHz, while plot2 has same number of samples with sampling rate at 10KHz. Two plots will share same X-Axis, and X-axis should show time based information. One way to convert X-Axis to be time based is to use ValueFormatter approach .
Snippet
protected override string FormatCore<TData>(TData value, ValuePresenterArgs args) { double dValue; try { // Try to covert axis value to a double dValue = Convert.ToDouble(value); switch (AxisValueType) { case AxisValueTypeEnum.Time: // Convert value to corresponding time if (_deltaT > 0) { dValue = _deltaT * dValue + _offsetT; return string.Format(EngineeringFormatInfo.Default, "{0:s2's'}", dValue); } else { return base.FormatCore<TData>(value, args); }
This works perfectly if there is only one plot or plots having same sampling rate. In the case mentioned above, only the later renderred plot will have right time info on x-axis.
One way to address this is to use scatter plot to provide time based data. However, it seems that scatter plot is mush slower. Are there any other solutions?
Thanks!
Solved! Go to Solution.
10-25-2017 01:06 PM
The closest existing type that supports samples with a fixed sample rate is the Spectrum type:
double[] samples = ...; double sampleRate = ...; // e.g. 1 kHz = 1.0 / 1000.0
var waveform = Spectrum<double>.FromArray1D( samples ); waveform.FrequencyIncrement = sampleRate;
10-25-2017 07:44 PM
Paul, thanks for the suggestion! Using Specturm.FrequencyIncrement does set the x-axis value at per plot basis.