Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Continue from maximum xAxis value

Hello,

 

can somebody please help me with the following WavefromGraph-problem:

 

I have a WaveformGraph with one XAxis. Attached to this graph there are many plots each plot have its very own YAxis but are sharing one and the same XAxis (the default one of the graph).

I set the default increment to 0.5 seconds each time a value is appended using PlotYAppend(double data). So far so good, here comes the problem I am not able to solve, this drives me mad:

 

I'm adding, for example, three plots and updating values on these calling PlotYAppend() .... and finish plotting after, let's say, 5 seconds. Then I need to add two new plots which append data by using PlotYAppend() but for this two plots I want them to start plotting where the last (maximum) plot I plotted before has ended (here in this example: start from second 5). Although all the plots are sharing the same XAxis all plots start from second 0.

 

How can I achieve the above mentioned behaviour?

 

0 Kudos
Message 1 of 8
(4,599 Views)

Hello -

 

One thing that may work depending upon your application would be to use PlotY instead of PlotYAppend for your first plotting operation per plot.  This way, you can use the overload that includes an offset - allowing you to determine where plotting begins from.

 

NickB

National Instruments

0 Kudos
Message 2 of 8
(4,575 Views)

Hello nickb,

 

thanks for your suggestion, this however doesn't work since PlotY removes all previous points/history of the plot. What I need is actually something that is able to surpress line interploation between two specific points, say:

 

point(0,0) -> point(100,10) => Draw no line between, i.e. do not interpolate between these two points.

 

Best regards,

 

 

0 Kudos
Message 3 of 8
(4,565 Views)

I attached a picture for better understanding what I want to achieve.

 

0 Kudos
Message 4 of 8
(4,562 Views)

Hi there,

 

As I understood from the picture that you have attached, the append should start from the 5 seconds on the x-axis.

When you add a new plot, you can set the WaveformPlot.DefaultStart property which tells the graph where to start plotting.

 

If this is not what you are looking for, please attach a sample project and detail us about the requirement so that we can help you better.

 

Vijet Patankar

National Instruments

0 Kudos
Message 5 of 8
(4,527 Views)

Hello vcp,

 

I know the DefaultStart property, the problem is that the gap should be made in one and the same plot. So this is not a different plot where I could set the DefaultStart property.

 

0 Kudos
Message 6 of 8
(4,521 Views)

You can make a plot look broken in several ways.

 

Solution 1: Easy way

 

Set WaveformPlot.ProcessSepcialValues to true. Now, in the data plot Double.Nan to get a break in the plot.

 

 

            waveformPlot1.ProcessSpecialValues = true;
waveformPlot1.PlotYAppend(new double[] { 2, 3, 7, 5, double.NaN, double.NaN, 6, 9, 8, 4 });

Solution 2:  Not so easy way

 

1) Hook on to the Plot.BeforeDraw, and cancel the plot drawing. And do the following in the event handler.

2) Get the pixel coordinates for the break using WaveformPlot.Map(..). (Here we calculate start position and end position of the break in the pixel coordinates from the data coordinates).

3) Draw the plot to a temp Bitmap.

4) Once you know where the break appears in the pixel coordinates, use  Bitmap.SetPixel(...) method to set pixels in the rectangular region to Color.Transparent.

5) Use the grahics object from the event args to draw an image on the Plot area bounds.

6) Done.

 

Hope this helps.

 

Vijet Patankar

NationalInstruments.

    class MyPlot : WaveformPlot
    {
        int stopDrawingPoint = 2, skipPoints = 2;

        public int StopDrawingPoint
        {
            get
            {
                return stopDrawingPoint;
            }
        }

        public int SkipPoints
        {
            get
            {
                return skipPoints;
            }
        }

        //protected override void OnBeforeDraw(BeforeDrawXYPlotEventArgs e)
        //{
        //    e.Cancel = true;

        //    Graphics g = e.Graphics;
        //    double[] xData = e.Plot.GetXData();
        //    double[] yData = e.Plot.GetYData();

        //    double[] xDataBeforeBreak = GetPointsBeforeBreak(xData);
        //    double[] xDataAfterBreak = GetPointsAfterBreak(xData);
        //    double[] yDataBeforeBreak = GetPointsBeforeBreak(yData);
        //    double[] yDataAfterBreak = GetPointsAfterBreak(yData);

        //    Bitmap b = new Bitmap(e.Bounds.Width, e.Bounds.Height);
        //    Graphics gg = Graphics.FromImage(b);
        //    e.Plot.DrawLines(new ComponentDrawArgs(gg, e.Bounds));
        //    g.DrawImage(b, e.Bounds.Location);

        //    //PointF[] pointsBeforeBreak = e.Plot.MapDataPoints(e.Bounds, xDataBeforeBreak, yDataBeforeBreak);
        //    //g.DrawLines(new Pen(e.Plot.LineColor), pointsBeforeBreak);

        //    //PointF[] pointsAfterBreak = e.Plot.MapDataPoints(e.Bounds, xDataAfterBreak, yDataAfterBreak);
        //    //g.DrawLines(new Pen(e.Plot.LineColor), pointsAfterBreak);
        //}

        protected override void OnBeforeDraw(BeforeDrawXYPlotEventArgs e)
        {
            e.Cancel = true;

            Graphics g = e.Graphics;
            double[] xData = e.Plot.GetXData();
            double[] yData = e.Plot.GetYData();

            double[] xDataBeforeBreak = GetPointsBeforeBreak(xData);
            double[] xDataAfterBreak = GetPointsAfterBreak(xData);
            double[] yDataBeforeBreak = GetPointsBeforeBreak(yData);
            double[] yDataAfterBreak = GetPointsAfterBreak(yData);

            PointF[] pointsBeforeBreak = e.Plot.MapDataPoints(e.Bounds, xDataBeforeBreak, yDataBeforeBreak);
            g.DrawLines(new Pen(e.Plot.LineColor), pointsBeforeBreak);

            PointF[] pointsAfterBreak = e.Plot.MapDataPoints(e.Bounds, xDataAfterBreak, yDataAfterBreak);
            g.DrawLines(new Pen(e.Plot.LineColor), pointsAfterBreak);
        }

        private double[] GetPointsAfterBreak(double[] data)
        {
            double[] newData = new double[data.Length - (stopDrawingPoint + skipPoints)];
            for (int i = 0; i < newData.Length; i++)
            {
                newData[i] = data[i + stopDrawingPoint + skipPoints];
            }

            return newData;
        }

        private double[] GetPointsBeforeBreak(double[] data)
        {
            double[] newData = new double[stopDrawingPoint];
            for (int i = 0; i < stopDrawingPoint; i++ )
            {
                newData[i] = data[i];
            }

            return newData;
        }
    }
0 Kudos
Message 7 of 8
(4,515 Views)

Thanks! This solution (Solution 1) works perfectly!!

 

0 Kudos
Message 8 of 8
(4,501 Views)