LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Graph refresh and plot deleting

Hi
I have an issue with a graph control I am using the code below to plot my data on the graph on timer events, but even if I set the attribute of the graph to not retain plot on the graph the graph does stack all plots, I have tried to delete plot half the time with my "deleteflag code" but it still does refresh too fast .
I want to keep the same timer event frequency tomake sure all points are plotted but I d like the graph to be smoothly refreshed


int CVICALLBACK GraphTimer_CB (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{   
    double *Time;
    char *RampPatternString;
    double *Sum;
    double RampPattern[500];
    double *AnalogInputsArrayWithTickCountsVal;
    
                    if (deleteflag ==1)
                {
                    DeleteGraphPlot (dvdxt,DVDXT_SpeedTorqGraph ,-1 , VAL_DELAYED_DRAW); 
                    deleteflag = 0;
                }
                else deleteflag = 1;

    
    switch (event)
    {
        case EVENT_TIMER_TICK:
            
            if (StartTimerCallback!=0)
            {
                Sum=(double*)malloc(100*sizeof(double));
                RampPatternString=(char*)malloc(4440*sizeof(char));
                          
                SetCtrlAttribute(dvdxt, DVDXT_SpeedTorqGraph, ATTR_ACTIVE_YAXIS, VAL_LEFT_YAXIS);  
            
                //PlotY(dvdxt, DVDXT_SpeedTorqGraph,SpeedArray,500, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
            
                PlotWaveform(dvdxt, DVDXT_SpeedTorqGraph, SpeedArray, 500, VAL_DOUBLE, 1, 0, 0, 0.0002, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
                
                SetCtrlAttribute(dvdxt, DVDXT_SpeedTorqGraph, ATTR_ACTIVE_YAXIS, VAL_RIGHT_YAXIS);
            
                //PlotY(dvdxt, DVDXT_SpeedTorqGraph,TorqueArray,500, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE);
                
                PlotWaveform(dvdxt, DVDXT_SpeedTorqGraph, TorqueArray, 500, VAL_DOUBLE, 1, 0, 0, 0.0002, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE);
                
                SetCtrlVal(dvdxt, DVDXT_Pressure_indicator, PressureVal);
                
                Ramp(500, TimeIndex, TimeIndex + (500*0.0002),RampPattern);
                
                TimeIndex += 500*0.0002;
                
                SetCtrlVal(dvdxt, DVDXT_TimeIndex, TimeIndex);
                             
                
            
            }
            
            break;
    }
    return 0;
}

Thanks

Olivier
0 Kudos
Message 1 of 2
(4,228 Views)

Hello Olivier,

The reason the update isn't smooth is because when you plot the first array, the graph redraws at that point, and it redraws without the second plot. Then, a few milliseconds later, it draws again when you plot the second array. This creates flashiness. To avoid that, before plotting the first array, set the ATTR_REFRESH_GRAPH attribute to FALSE. Then, after plotting both arrays, set it back to TRUE. That should result in a single drawing operation, without any flashing.

And, of course, you need to continue passing VAL_DELAYED_DRAW to the DeleteGraphPlot function, otherwise it would redraw at deletion time as well.

Speaking of the delete operation, you really should move that code under the EVENT_TIMER_TICK case. Since this is a timer callback, it doesn't make a big difference (the only other event that is sent for timer controls is EVENT_DISCARD). But in the future, new events can always be added for a control, and then your code might start deleting plots unexpectedly.

Of course I might be assuming too much about how you want to delete the plots, given that you're only deleting every other iteration.

Luis

0 Kudos
Message 2 of 2
(4,217 Views)