Freigeben über


Grouping Data in Chart Controls

Grouping replaces a sequence of data points in a series with one grouped point. The X and Y values of each grouped point are calculated using a specified formula in combination with the original values of every point used.

Grouping is especially useful when there are many data points, making it easier to spot trends in a chart.

Before grouping your data in a series, make sure that the data in the series is sorted by X value in ascending order. For more information on sorting, see Sorting Data.

Grouping Formulas

Grouping is accomplished using the DataManipulator object. There are two types of grouping: by axis label and by interval. Set the DataManipulator.IgnoreEmptyPoints property to false if you wish to treat empty points as points with zero values.

When you invoke the Group and GroupByAxisLabel methods, you must specify a formula. You can specify a separate formula for some or all of a data point's Y values. At least one formula must be provided, in which case it is used to calculate all the Y values of a point.

The format of the formula parameter is:

"formula[, value:formula, [value:formula[,...]]]"

where formula is one of the formula names and value is the name of the data point's Y value the formula is applied to (For example, "Y2").

For example, if you use the formula string "AVE, X:CENTER, Y2:MAX" in a grouping procedure, it results in:

  • The grouped points being plotted in the center of their interval.

  • The maximum Y2 value of all input points being used for all Y2 values of the grouped points.

  • An average of all other Y values being calculated.

Refer to the table below for a list of these of formulas, and an explanation of what they do. Note that for X values, the default formula (that gets applied if one is not specified) is the "First" formula. Also it is worthy of mention that formulas for X values merely determine where the resulting data points will be plotted for the specified interval (for example, along the left or right boundary of an interval or in the center of an interval).

Note

By default, the "FIRST" formula is used to calculate the X values.

Formula

Description

Used for X-Value

AVE

The average value of all data points within the given interval.

No.

MAX

The maximum value of all data points within the given interval.

No.

MIN

The minimum value of all data points within the given interval.

No.

SUM

The total value of all data points within the given interval.

No.

LAST

The last value of all data points within the given interval.

Yes. New data points are drawn at the right-most margin of intervals.

FIRST (Default)

The first value of all data points within the given interval.

Yes. New data points are drawn at the left-most margin of intervals.

HiLoOpCl

Calculates the largest, smallest, opening and closing values. Opening value is the first value in the interval, while the closing value is the last value for the interval.

Note

This formula returns four Y values, and should only be used for chart types that use four Y values (e.g. Candlestick charts).

No.

HiLo

The largest and smallest of all data points within the given interval.

Note

This formula returns two Y values, and should only be used for chart type that use two Y values (e.g. Bubble charts).

No.

Count

The number of data points that have been grouped into one point.

No.

DistinctCount

The number of data points that have been grouped into one point. Data points that have the same primary Y values are considered one point.

No.

Variance

The variance between all data points within the given interval.

No.

Deviation

The deviation between all data points within the given interval.

No.

Center

The deviation between all data points within the given interval.

Yes. New data points are drawn at the center of intervals.

Grouping by Interval

Use the Group method to group by interval. This method splits series data points into intervals using their X values, and then replaces each interval with one point.

The following code demonstrates how to group by yearly quarters and store the result series in a series named "ResultSeries".

' Group points by year quarters.
Chart1.DataManipulator.Group("AVE", 3, IntervalType.Months, "MySeries", "ResultSeries")
// Group points by year quarters.
Chart1.DataManipulator.Group("AVE", 3, IntervalType.Months, "MySeries", "ResultSeries");

Grouping by Axis Label

Use the GroupByAxisLabel method to group by axis label. This method groups all data points with the same AxisLabel property value, and calculates the result Y value using the formula you specify.

Note

As a result of this grouping operation, data points will be sorted by their respective AxisLabel property in ascending order.

The code below groups points that represent discreet sales. It assumes that the X values of the data points are bound to a string that stores the salesperson names, and each salesperson name is stored using the AxisLabel property. It adds up the sale amounts for each salesperson name and outputs the totals by salesperson to the input series (the default output series).

' Group by salesperson name, and display total sale amounts.
Chart1.DataManipulator.GroupByAxisLabel("SUM", "GoldMedals")
// Group by salesperson name, and display total sale amounts.
Chart1.DataManipulator.GroupByAxisLabel("SUM", "GoldMedals");

Grouping Multiple Series

Group multiple series by specifying a comma-separated list of the series names in the Group or GroupByAxisLabel method.

Warning

If output series are specified, then the number of output series must be the same as the number of input series. Otherwise, the method throws an exception.

If you specify "*" as the input series, the method groups all series in the Chart.Series collection.

This example groups two series: MySeries1 and MySeries2.

' Group two series by week, using averaged Y values.
Chart1.DataManipulator.Group("AVE", 1, IntervalType.Weeks, "MySeries1, MySeries2")
// Group two series by week, using averaged Y values.
Chart1.DataManipulator.Group("AVE", 1, IntervalType.Weeks, "MySeries1, MySeries2");

See Also

Reference

System.Windows.Forms.DataVisualization.Charting

System.Web.UI.DataVisualization.Charting

Other Resources

Data Binding and Manipulation