Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Chart User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

15.7 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.

15.7.1 Using the Curve Fit Chart

To set up a Curve Fit chart:

  1. Create an OCCurveFitItem object somewhere.

  2. Create two data buffers (optional).

  3. Initialize the data buffers with your X and Y data.

  4. Call SetData((int nSize, double* pInX, double pInY) to provide the data to the OCCurveFitItem instance.

  5. Call SetXRange(double dMinX, double dMaxX) to restrict the range of X data used to compute the fit (optional).

  6. Call SetupComponent() to create the display and optional title for the internal SRGraph member.

  7. Call SetFitType(int nType) to specify form of the desired curve. The supported types are listed in the Table 21.

  8. Finally, call ProcessData() to perform the computation.

  9. In your OnDraw() function call the DrawComponentList() function of OCCurveFitItem's internal SRGraph object to display the chart.

Table 21: Enumerated curve fit types

FIT_NONE 0  
FIT_1ST_ORDER_POLY 1 y = a0 + a1*x
FIT_2ND_ORDER_POLY 2 y = a0 + a1*x + a2*xˆ2
FIT_3RD_ORDER_POLY 3 y = a0 + a1*x + a2*xˆ2 + a3*xˆ3a
FIT_4TH_ORDER_POLY 4 y = a0 + a1*x + a2*xˆ2 + ... + a4*xˆ4
FIT_5TH_ORDER_POLY 5 y = a0 + a1*x + a2*xˆ2 + ... + a5*xˆ5
FIT_6TH_ORDER_POLY 6 y = a0 + a1*x + a2*xˆ2 + ... + a6*xˆ6
FIT_7TH_ORDER_POLY 7 y = a0 + a1*x + a2*xˆ2 + ... + a7*xˆ7
FIT_8TH_ORDER_POLY 8 y = a0 + a1*x + a2*xˆ2 + ... + a8*xˆ8
FIT_9TH_ORDER_POLY 9 y = a0 + a1*x + a2*xˆ2 + ... + a9*xˆ9
FIT_EXPONENTIAL 10 y = a0*eˆ(a1*x)
FIT_LOGRITHMIC 11 y = a0*ln(a1*x)
FIT_POWER 12 y = a0*10ˆ(a1*x)
FIT_INVERSE 13 y = a0 + a1*xˆ(-1)
FIT_INVERSE_SQUARE 14 y = a0 + a1*xˆ(-2)
FIT_SINE 15 y = a0*sin(a1*x+a2) + a3

Here is an example:

Figure 136: Sample Curve Fit chart

The CurveFitChart sample application distributed with Objective Chart (in <installdir>\Samples\Chart\Utility Toolkit) is a full implementation of the Curve Fit chart. The view class contains the OCCurveFitItem object and displays the chart. The view also supports several user interface enhancements.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.