Using graphics to plot xy-graph

xy-graph in pvbrowser

This is an example for an xy-graph. Input a custom widget "QDraw" in Qt designer and copy the following code. You can output as many lines as you want.

//<snip>
#include <math.h>
//<snip>
typedef struct // (todo: define your data structure here)
{
  float x[100];
  float y[100];
  int   n;
}
DATA;

// _begin_of_generated_area_ (do not edit -> use ui2pvc) -------------------

// our mask contains the following objects
enum {
  ID_MAIN_WIDGET = 0,
  draw1,
  ID_END_OF_WIDGETS
};
//<snip>
// _end_of_generated_area_ (do not edit -> use ui2pvc) ---------------------
//<snip>
static int drawGraphic(PARAM *p, int id, DATA *d)
{
int x,y,w,h,fontsize;

  x = 80;
  y = 30;
  w = 400;
  h = 300;
  fontsize = 10;

  gBeginDraw  (p,id);
  gSetColor   (p,BLACK);
  gSetFont    (p,TIMES,fontsize,Normal,0);
  gBoxWithText(p,x,y,w,h,fontsize,"phi","sin(phi)",NULL);
  gXAxis      (p,0,1.0f,2.0f*3.141592654f,1);
  gYAxis      (p,-1.5f,0.5f,1.5f,1);
  gXGrid      (p);
  gYGrid      (p);
  gSetColor   (p,RED);
  gSetWidth   (p,4);
  gLine       (p,d->x,d->y,d->n);
  gEndDraw    (p);
  return 0;
}

static int showData(PARAM *p, DATA *d)
{
  if(p == NULL) return 1;
  if(d == NULL) return 1;
  generatedShowData(p,d);
  drawGraphic(p,draw1,d);
  return 0;
}
//<snip>
int show_mask1(PARAM *p)
{
  DATA d;
  char event[MAX_EVENT_LENGTH];
  char text[MAX_EVENT_LENGTH];
  char str1[MAX_EVENT_LENGTH];
  int  i,w,h,val,x,y,button;
  float xval, yval;

  defineMask(p);
  memset(&d,0,sizeof(DATA));
  for(i=0; i<100; i++) // for testing purposes we set a sinus curve
  {
    xval = (((float) i) * 2.0f * 3.141592654f) / 100.0f;
    d.x[i] = xval;
    d.y[i] = (float) sin(xval);
  }
  d.n = 100;
//<snip>
}