Curve Fit Chart

The Curve Fit Chart calculates and plots a least squares fit to a series of observed data points (X,Y). The functional form of the curve fit can be selected from a variety of supported equations. The Curve Fit chart is implemented in the OCCurveFitItem class. Several other classes (defined in curvefit.cpp) are used internally to perform the least squares fit calculations. A CX_GRAPH_XYSCATTERG_EX graph plots the data. Linear or logarithmic scaling can be applied to the X and Y axes independently. Optionally, the fit information (equation with computed coefficients and correlation coefficient) are displayed in an SRGraphTitleResizeable component.

Internally, the Curve Fit chart maintains four groups of data. The first two groups store the raw (or input) X and Y data, which are plotted as blue dots. The third and fourth groups store points generated to describe the equation of the fit, which is plotted as a red line.

The input data is passed to OCCurveFitItem::SetData(int nSize, double* pInX, double pInY) as two arrays of doubles. Alternatively, OCCurveFitItem will create its own buffers if both pInX and pInY are NULL. In that case, OCCurveFitItem allocates and deallocates its own buffers, but the buffers must be initialized -- by calling SetValue() -- before the curve fit is generated or the chart is drawn.