how to display several graphs with the widget RtTrend ?

Hi!I just want to display some sine waves on the screen just like the trend demo shows.However after reading something,I found the helpviewer not very clear on how to use the widget RtTrend.I don’t know how to add my data to the trend and how to display them dynamically.Is there anyboby familiar with PHAB?Any suggestions?Some programming examples with the usage of RTTREND will be greatly appreciated!My email is:
erikingdom@sohu.com
Thanks!

a simple example …

QNX 4.25

[code]#include <Pt.h>
#include <math.h>

#define START_X .0
#define WIDTH 628
#define SAMPLES 628
#define TRENDS 2
#define HEIGHT 200
#define STEP (2. / HEIGHT)

PtWidget_t *trend;

int main ()
{
int i;
double x, y;
PtWidget_t *window, *timer;
PtArg_t arg[10];
PhDim_t dim;
short trend_min, trend_max, trend_count;
short trend_data [SAMPLES * TRENDS];

if (PtInit(NULL) == -1)
	return -1;

dim.w = WIDTH;
dim.h = HEIGHT;
PtSetArg(&arg[0], Pt_ARG_DIM, &dim, 0);

if ((window = PtCreateWidget(PtWindow, NULL, 1, &arg[0])) == NULL)
	return -1;

trend_min = -(HEIGHT / 2);
PtSetArg(&arg[1], Rt_ARG_TREND_MIN, trend_min, 0);
trend_max = HEIGHT / 2;
PtSetArg(&arg[2], Rt_ARG_TREND_MAX, trend_max, 0);
trend_count = TRENDS;
PtSetArg(&arg[3], Rt_ARG_TREND_COUNT, trend_count, 0);

if ((trend = PtCreateWidget(RtTrend, window, 4, &arg[0])) == NULL)
	return -1;

for (i = 0, x = START_X; i < SAMPLES; i++, x += STEP)
{
	y = sin(x) / STEP;
	trend_data[i] = y;
}

for (i = 0, x = START_X; i < SAMPLES; i++, x += STEP)
{
	y = sin(4 * x) / STEP / 4;
	trend_data[SAMPLES + i] = y;
}

PtRealizeWidget(window);
RtTrendChangeData(trend, trend_data, 0, SAMPLES);
PtMainLoop();

return 0;

}[/code]
compile with

cc trend.c -lphoton -lphrtlib

QNX 6.2.1

[code]#include <Pt.h>
#include <math.h>

#define START_X .0
#define WIDTH 628
#define SAMPLES 628
#define TRENDS 2
#define HEIGHT 200
#define STEP (2. / HEIGHT)

PtWidget_t *trend;

int main ()
{
int i;
double x, y;
PtWidget_t *window, *timer;
PtArg_t arg[10];
PhDim_t dim;
short trend_min, trend_max, trend_count;
short trend_data [SAMPLES * TRENDS];

if (PtInit(NULL) == -1)
	return -1;

dim.w = WIDTH;
dim.h = HEIGHT;
PtSetArg(&arg[0], Pt_ARG_DIM, &dim, 0);

if ((window = PtCreateWidget(PtWindow, NULL, 1, &arg[0])) == NULL)
	return -1;

trend_min = -(HEIGHT / 2);
PtSetArg(&arg[1], Pt_ARG_TREND_MIN, trend_min, 0);
trend_max = HEIGHT / 2;
PtSetArg(&arg[2], Pt_ARG_TREND_MAX, trend_max, 0);
trend_count = TRENDS;
PtSetArg(&arg[3], Pt_ARG_TREND_COUNT, trend_count, 0);

if ((trend = PtCreateWidget(PtTrend, window, 4, &arg[0])) == NULL)
	return -1;

for (i = 0, x = START_X; i < SAMPLES; i++, x += STEP)
{
	y = sin(x) / STEP;
	trend_data[i] = y;
}

for (i = 0, x = START_X; i < SAMPLES; i++, x += STEP)
{
	y = sin(4 * x) / STEP / 4;
	trend_data[SAMPLES + i] = y;
}

PtRealizeWidget(window);
PtTrendChangeData(trend, trend_data, 0, SAMPLES);
PtMainLoop();

return 0;

}[/code]
compile with

cc trend.c -lph -lm

Thank you,Mezek!

One more question:How to make the curve move just like the trend demo shows,like from right to left?And my qnx version is 4.25!Thanks!

Actually the program for QNX4.25 can work well wih no change .However,it seemed that the program didn’t work if the constant TRENDS changed to 1 in QNX4.25!I don’t know why.Any idea?

thats because of that second for-cycle, it exceeds boundaries of the array trend_data
i put there the TRENDS to show where the number of trends come into play in an example of 2 trends

except the compiling sentence. Is the code of program different from each other. It looks the same.

in 4.25 the widget is called RtTrend and used function RtTrendChangeData()
in 6.2.1 it is PtTrend and PtTrendChangeData()

I see, thanks.