How QtChart captures data
While the goal of the QtChart application is to present a completely accurate, paper chart-recorder like plot of the data, there are practical limitations and differences. The following describes these limitations and differences and how they are dealt with.
Analog vs Digital
A traditional paper and pen chart recorders are analog electro-mechanical devices. The input data is an analog electrical signal that is passed through analog amplifiers and used to control the position of an ink pen drawing a line on a piece of paper as the paper moves under it. The period of time over which data is maintained is limited only by how much paper and ink you have. The resolution of the visual output (how much detail it captures) is a function of how fast and how far the needle moves in response to changes in the input signal, the thickness of the line it draws, and the speed at which the paper moves.
The QtChart application is a computer program. The input data is a set of discrete data points specifying an approximation of the value of some signal at specific points in time. The period of time over which data is maintained is limited by how much memory is available. The resolution of the visual output is limited by the number, accuracy, and timing of the data points, the number of data points stored over a given interval, and the number of pixels on the screen or printer used to produce a visual representation of the data.
What QtChart actually captures
The input data that QtChart uses is a set of data points, where each data point specifies a value (the Y-coordinate) and a time (the X-coordinate). It has no control over the number or timing of these data points, or the resolution of their values. QtChart's job is to produce a visual chart-recorder style plot that represents the data as accurately as possible within the constraints that it must work.
One of the constraints that QtChart works with is a fixed amount of memory. Given that QtChart does not know how many data points it will receive over time, it is not practical to simply save them all. Eventually it will run out of memory. And if the time between data points is small enough, it might not even be able to save enough points to cover the period of time over which it is supposed to produce a plot.
To deal with these practical limitations, while still retaining enough information to produce a reasonably accurate plot of the data, QtChart stores data in "segments", where each segment stores information about a fixed interval of time.
Each segment contains the following information:
- The earliest time
- The minimum value
- The maximum value
- The latest time
Note that, depending upon the number of points received during a segment's interval, and the values they had, more than one of these properties might be satisfied by the same point.
Why capture that information?
Given that we usually can't save all the data points, the above method maintains several key aspects of the original data:
Now compare these to the ways the data can be filtered for display:
As long as the time interval for each segment is kept small enough (preferably one segment = one pixel on the screen), then the plot drawn from this filtered version of the original data will be nearly identical to what would be plotted if the individual data points had been used.
The only significant difference occurs when we change the interval size. Ideally we would recompute all these values from the original data points, but they are no longer available. But even this error is minimized, by treating the filtered values as datapoints themselves, and mapping the data we do have into the new interval size.
So, by carefully selecting how the input data is filtered, and how ALL the data points contribute to the end result, it is possible to produce a very accurate representation of the original data without having to store all the original data.
Minimizing the effect of changing the Sec/Div:
To keep things simple, QtChart maintains a fixed # of segments as described above. The segments are used in a "round-robbin" fashion, so when it gets to the end of the list, it simply starts over at the beginning.
QtChart does two things to minimize the effect of changes to the horizontal/time scale for the chart display.
First, it maintains twice as many segments as it needs for the current time scale setting. This means that the
period of time to display can be doubled and there will still be enough data to fill the chart window.
Second, existing segments are not altered at the time the scale is changed. The scale setting is used only to determine the span of time represented by newer segments. So the data in existing segments is left intact until they are reused, allowing the time scale to be rapdily changed up and down without affecting the accuracy of anything but the most recent portion of the display.