Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Change X-Axis value for specific plot on demand?

Solved!
Go to solution

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. 

  1. first plot plot1, x-axis time range will be 0mS to 1s
  2. then plot plot2, x-axis time range now become 0mS to 100mS. This looks good for plot2, but wrong for plot1.

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!

 

 

0 Kudos
Message 1 of 3
(2,656 Views)
Solution
Accepted by topic author Bob.Ter

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;
~ Paul H
0 Kudos
Message 2 of 3
(2,634 Views)

Paul, thanks for the suggestion! Using Specturm.FrequencyIncrement does set the  x-axis value at per plot  basis. 

0 Kudos
Message 3 of 3
(2,622 Views)