ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Question about sampleSize, initialFullRange & ChartUpdateTimer.
Posted by choynsg on Oct-13-2023 09:43
Hello Peter,

I don't quite understand how the code below works in MFC realtimemultithread.
I am still using the code below without a clear understanding.
Would you explain the detailed operation with some examples?
I would also like to know the relationship with the xAxis range.

// The number of samples per data series used in this demo
static const int sampleSize = 10000;

// The initial full range is set to 60 seconds of data.
static const int initialFullRange = 60;

// The chart update rate is set to 100ms
SetTimer(ChartUpdateTimer, 100, 0);

Thank you in advance.

Best regards

  Re: Question about sampleSize, initialFullRange & ChartUpdateTimer.
Posted by Peter Kwan on Oct-13-2023 15:41
Hi choynsg,

At first, the chart has no data point. Later, the chart has one data point, then two data points, and more and more data points. If this continues, the computer will run out of memory and the program will crash. To avoid this, we must limit the memory used by throwing away the oldest data points.

The sampleSize is the maximum number of data points to keep. If there are too many data points, the oldest data points will be removed.

Initially, there is only one data point (let say the point is at 2023-10-12 10:34:67.00), then what should the x-axis scale be? You cannot define an axis scale with a single data value. You need a data range to define the axis. The initialFullRange defines the x-axis range to use initially. The full range will be updated by the sample code when more and more data comes in.

The full range is the range displayed when the chart is fully zoomed out. The actual x-axis range seen on the chart is controlled by the user using the zooming and scrolling features.

The ChartUpdateTimer configures how fast the chart will update. In the sample code, it is set to 100ms. The chart update rate can be different from the data rate. For example, in a digital oscilloscope, there can be millions of data points per second. We cannot update the chart that fast as a normal computer screen is only working at 60Hz, and human being cannot see things that update too fast. In practice, for charting, updating the chart at 50 - 100ms is quite reasonable.

In the CRealtimemultithreadDlg sample code, when the data comes in from a separate thread (in OnData), it will be stored in a buffer. When the chart needs to update (in OnChartUpdateTimer), it will copy the data from the buffer and append them to the data arrays used by the chart. If there are too much data (more than sampleSize), it will remove the old data. Then it is update the chart.

There is another multi-threading real-time chart example in the ChartDirector 7 sample code called "Mega Real-Time Chart with Zoom/Scroll and Track Linel":

In this sample code, the sampleSize is set to 10000000 and the random number generator is producing 1000 x3 = 3000 data points per second.

Best Regards
Peter Kwan

  Re: Question about sampleSize, initialFullRange & ChartUpdateTimer.
Posted by choynsg on Oct-13-2023 19:59

Hello Peter,

My scenario is below.

Two hours worth of data collected every second must be displayed in one plot area.
In other words, the data from the start to 2 hours must be displayed every second without horizontal scrolling of the plot area.
After 2 hours, horizontal scrolling is required.
The total number of data series (Waveforms) to be plotted is 40.
Because I need to compare the correlation between each waveform, I need to display all data series in one plot area.

Q1) Are there any problems if the settings that meet the conditions of the chart above are set as follows?

static const int initialFullRange = 7200; // 120minutes * 60sec
static const int sampleSize = 7200; // Value for collecting 1 data per second and displaying 2 hours of data in one plot area

double m_timeStamps[sampleSize];
double m_dataSeriesA[15][sampleSize];
double m_dataSeriesB[5][sampleSize];
double m_dataSeriesC[3][sampleSize];
double m_dataSeriesD[2][sampleSize];

(The y-axis values of each data series were very different, so they were divided into A, B, C, and D)

OnData period is 0.5 or 1 second
OnChartUpdateTimer period is 1 second

Q2) Will there be any problem if I use CRealtimemultithreadDlg sample under the plotting conditions above?
Or would it be better to use the Mega Real-Time Chart with Zoom/Scroll and Track Line sample?

I would like to ask for your valuable advice.

Thank you in advance.

Best regards

  Re: Question about sampleSize, initialFullRange & ChartUpdateTimer.
Posted by Peter Kwan on Oct-14-2023 02:33
Hi choynsg,

Your code will configure the chart to store the last 2 hours of data. For example, after 4 hours, only the data for the 3rd and 4th hours are stored.

If this is what you want, then configuration is OK. As there are less than 1 million data points in total (40 x 2 x 3600 = 288000), I think the CRealtimemultithreadDlg is sufficient.

(The "Mega Real-Time Chart with Zoom/Scroll and Track Line" uses the ChartDirector DataAccelerator object, which can handle up to 1 billion data points.)

Best Regards
Peter Kwan