09-17-2008 08:26 AM
I need to solve a problem similar to the problem described here.
I am using a WaveformGraph. I would like to paint the Xaxis values myself. My thinking (sorry) is that it would be nice to be able to override the XAxis class to replace the displayed values as they are being painted.
The data displayed is your standard doubles over time variety with each data point representing a sample taken on a regular interval (2ms). I would like to display the data that is collected over several days but I would not like to show the gaps that will result when relying on the actual sample times. Instead I thought I could set my x values to be the offset(ms) from the beginning and instead of painting the offset values on the xaxis, do a little date calculation to paint the date value as needed. This would allow me adjust for the gaps as needed. Alas, I am not finding an overridable event in XAxis.
Is there another path for me to explore?
Solved! Go to Solution.
09-19-2008 01:25 PM - edited 09-19-2008 01:25 PM
Hello jsytniak,
While it may not exactly address your needs, I have come up with a rather contrived example that I think shows what you are looking for, and hopefully you can find some pieces of it helpful. Below is a screenshot of the end result:
You will notice that at the transition point, there are about 20 seconds missing, which could just as easily be days. The code behind this example is below, with the important pieces highlighted:
namespace CustomXAxis
{
public partial class Form1 : Form
{
public Form1()
{
myFormatString customFormatString = new myFormatString();
InitializeComponent();
xAxis1.MajorDivisions.LabelFormat = customFormatString;
transitionAnnotation.Visible = false;
}
public static double startTime;
private void button1_Click(object sender, EventArgs e)
{
AnalogWaveform<double>[] dataWaveforms = new AnalogWaveform<double>[2];
double[] dataArray = new double[5000];
WaveformTiming timing = WaveformTiming.CreateWithRegularInterval(TimeSpan.FromSeconds(.002), DateTime.Now);
AnalogWaveformPlotOptions plotOptions = new AnalogWaveformPlotOptions(AnalogWaveformPlotDisplayMode.Time, AnalogWaveformPlotScaleMode.Raw);
for (int i = 0; i < 20000; i++)
{
if (i<5000)
dataArray[i] = Math.Sin(i*.01) * 10;
if(i==5001)
{
dataWaveforms[0] = AnalogWaveform<double>.FromArray1D(dataArray);
dataWaveforms[0].Timing = timing;
}
if (i > 14999)
dataArray[i - 15000] = Math.Sin(i*.01) * 8;
}
startTime = (double)DataConverter.Convert(dataWaveforms[0].Timing.StartTime, typeof(double));
dataWaveforms[1] = AnalogWaveform<double>.FromArray1D(dataArray);
timing = WaveformTiming.CreateWithRegularInterval(TimeSpan.FromSeconds(.002), DateTime.Now, TimeSpan.FromSeconds(5000 * .002));
dataWaveforms[1].Timing = timing;
waveformGraph1.PlotWaveforms<double>(dataWaveforms, plotOptions);
transitionAnnotation.XPosition = startTime + 5000 * .002;
transitionAnnotation.Visible = true;
}
}
public class myFormatString : FormatString
{
public myFormatString()
: base(FormatStringMode.DateTime, "h:mm:ss tt")
{
}
public override string FormatDouble(double value)
{
if (value < Form1.startTime + 5000 * .002)
return base.FormatDouble(value);
else
return base.FormatDouble(value + 10000 * .002);
}
}
}
If you've got any questions about my code, or if this doens't really fit what you were looking for, let me know, and I'll be happy to continue to look at it with you.
NickB
National Instruments
09-19-2008 01:41 PM
You appear to have nailed it. I'll post again after a take a close look.
Thanks.
Joe
09-23-2008 09:13 AM
Just to be certain.... you state that you are generating a 20 second gap in the data presented in the example. Isn't the gap 10 seconds?
The point is still made - I just want to be sure I am not missing something.
09-23-2008 12:46 PM
Hey Joe,
In my example, the gap was somewhat fudged. There are actually two things going on. I create two different waveforms, and populate them from an array that has no timing information associated with it. I then specify the timing associated with these two waveforms such that they will have no (or at least very little) gap between the two waveforms when plotted on the graph. This is done by adjusting the timing object associated with the waveforms such that the interval between each point it .002 seconds, and by adjusting the TimeOffset property of the second waveform.
The second thing that I do is in the overridden format double method where I check if the time period elapsed (the double value parameter) has been 10 seconds (meaning I have plotted all of the first waveform), and if it has, then I add 20 seconds to the elapsed time for the rest of the label strings. This tweny seconds is equvilent to the samples 5000-14999 that were not collected in my loop.Thus, at the point marked "Transition Point", there does indeed exist a 20 second gap.
The result of this is that the timing information associated with the second waveform *is not* correct, but it does display correctly on the graph.
Let me know if anything else remains unclear!
NickB
National Instruments
09-23-2008 02:25 PM - edited 09-23-2008 02:34 PM
My first response was probably a bit premature. Sorry.
I recognized most of what you explained in further detail. This is really close to what I need. But there are still some issues with accurracy.
I refactored the code a little make it easier to tweak some of the constants. I altered the date time format so that it shows milliseconds. I also added some cursors along with a little keyboard handling.
The cursors show something interesting - it appears that the x-axis is not lining up on the second plot. I understand that in reality the second plot timing values are *not correct* but your assertion that the labels are showing up properly is what I call into question. Clearly there is some sort of adjustment made. Maybe the formula in the custom formatter needs to be adjusted. I have assigned the tooltip and cursor label formats to the custom format string so I would think they would line up. They do not appear to be lining up. Simply zoom in near a major gridline and move the cursor along the plot to see the behavior
Refactored/enhancedUI form code attached.
Thanks.
Joe
PS - since your forum name is nickb I thought you might get a kick out of this one (hope a little fun is allowed)
09-23-2008 06:48 PM
Hey Joe,
Unless I just misunderstood what you were seeing, I think the issue is that you were assigning the standard FormatString to the LabelXFormat property of the cursors, ie:
cursor2.LabelXFormat = new FormatString(FormatStringMode.DateTime, "h:mm:ss.FFF");
If you change this to read cursor2.LabelXFormat = customFormatString, I think everything should look right for you. It is this LabelXFormat property that determines how the data is displayed to the user. Also, I noticed that you had set this for the tooltips that display when you hover your mouse cursor over the plot, and these also seemed to line up with the values shown on the XAxis. If I have misunderstood what you were getting at in your previous post, just let me know!
NickB
National Instruments
PS - I loved the video, I'm surprised that's the first time anyone has ever brought that to my attention...
09-23-2008 07:17 PM - edited 09-23-2008 07:25 PM
Nick -
Yes - I neglected to change that LableXFormat property, and of course the stuff will not line up if it is not run through the same formatter - duh! I feel shame. I really thought I had done that.
The only thing that kinda threw me was the gap and you are creating an offset on purpose. This looks like exactly what I was looking for. Now I just need to figure out a way to make the gap "disappear" as I will want my interface to have the second plot begin immediately to the right of the annotations (which I will also need). I'm sure that cannot be too hard to figure out, but if you want to throw me a bone, please fell free to share.
Thanks for you help. Glad you enjoyed the vid.
Joe
09-25-2008 10:51 AM
Nick -
I suppose we are doing something a little *outside of the box* here and I may have identified something that should be addressed.
I added a UI for adjusting the size of the time gap between the two plots. My method for adjusting should work - I think anyway. The second plot appears to adjust but XAxis does not adjust. The XAxis does adjust if I resize the form.
Joe
09-26-2008 04:40 PM
Hey Joe,
Thanks for the example, it looks great. The issue that you have noted where the xAxis does not appear to update has been observed, and we are investigating it under ID 128046. In the meantime, a possible workaround would be to toggle the visibility of the xAxis. While this looks a little hacky, I have not perceived any flickering when employing this technique. Thanks again for the feedback!
NickB
National Instruments