# Applying Formulas (Chart Controls)

Visual Studio 2010

You can perform statistical analysis and financial analysis on data series using the formulas provided by the Chart control in the Chart.DataManipulator property.

# Using Statistical Formulas

To use statistical formulas in a Chart object to perform statistical analysis on one or more Series objects, use the methods in the Chart.DataManipulator.Statistics property methods. For more information on each formula, see System.Windows.Forms.DataVisualization.Charting.StatisticFormula or System.Web.UI.DataVisualization.Charting.StatisticFormula.

All statistical methods that use one or more data series for their input data cannot use indexed data points. Before using a statistical formula method, do the following:

• Set the XValue property of all data points explicitly.

• Make sure that each series' XValueIndexed property is set to False.

# Using Financial Formulas

To perform financial analysis on one or more Series objects, use the Chart.DataManipulator.FinancialFormula method. For more information on each formula, see Financial Formulas.

#### To apply a formula

1. Perform all necessary data filtering or grouping. Use the Filter and Group methods in the DataManipulator object.

2. For formulas involving moving averages, set the DataManipulator object's StartFromFirst property to the preferred value.

3. Use the FinancialFormula method in the DataManipulator class to apply the formula of your choice.

Each formula has a specific set of requirements is implemented differently. See the respective topic for detailed information on each formula.

4. After applying certain formulas, the output data series does not have the same size as the input data series. To plot the two data series in the same chart, you may want to perform additional data filtering to make sure that each input data point has a corresponding output data point.

### Setting the StartFromFirst Property

Since the moving average of a specified period cannot be calculated for the first numeric data points, the DataManipulator.StartFromFirst property determines how these first data points are dealt with.

By default, StartFromFirst is set to False. When you use a formula that involves moving averages, the formula ignores the starting data points until it has enough data points to calculate the moving average. For example, if you want to calculate a 20-day moving average, the formula ignores the first 19 data points since there are not enough data points to calculate a 20-day moving average until the 20th day. However, if StartFromFirst is set to True, the formula calculates the moving average for the beginning points even though there are not enough data points yet. This gives you the advantage of having one moving average for each input data point in the series.

### Using the FinancialFormula Method

The FinancialFormula method takes up to four arguments in the following order.

Formula Name

Specify the type of the formula here with a FinancialFormula enumeration value. For example, specify

FinancialFormula.AccumulationDistribution

to invoke this method with the accumulation distribution formula.

The number of parameters, input and output, as well as the requirements for each parameter, change based on the formula you choose here.

Parameters

Some formulas require parameters, and some enable you to optionally supply them. A few formulas do not use parameters.

If a formula takes multiple parameters, specify them as a comma-separated string. For example, "2,true".

Input Values

Specify in a comma-separated string the names of instantiated Series objects to which you wish to apply the formula.

To specify a specific Y value to use for an input value, append a colon after the series name, followed by the Y value index. For example, "Series1:Y" points to the first Y value in Series1, and "Series1:Y2" points to the second Y value in Series1. If you do not specify a Y value, the formula uses the first Y value of the named series.

For example,

"Series1:Y,Series3:Y2,Series4"

Output Values

(Optional) Specify in a comma-separated string the name of instantiated Series objects to which you want to save the output. If you do not specify output values, the formula stores the first output value in the first listed input value, and so on. In this case, the method throws an exception if the number of input values is less than the number of output values.

To specify a specific Y value to use for an output value, append a colon after the series name, followed by the Y value index. For example, "Series1:Y" points to the first Y value in Series1, and "Series1:Y2" points to the second Y value in Series1. If you do not specify a Y value, the formula uses the first Y value of the named series.

For example, "Series1:Y,Series4".