Dundas Data Visualization Support Site
Dundas Support Site Home  |  Contact Us  |  Dundas Home  
Contact Us via Email
Home

Grouping Values Together

 

A useful piece of functionality in Dundas Chart (for .NET Enterprise Edition and for SharePoint) is to group data together and aggregate their values. For example, if you have more than one value for a given category and you would like them grouped together, you can take the sum (total), average, minimum, maximum, first, last or count of all of the values in the category.

This functionality is provided by some (but not all) data sources such as databases, so Dundas Chart allows this to be accomplished with a line or two of code. In Dundas Chart for SharePoint, you can write code by accessing the Chart Web Part's code editor from the down-arrow menu in the top-right corner of the web part, and choose the PostApplyData event, which lets you customize the data after it is added to the chart.

Here is an example of a dataset that contains two fields that could be used to categorize and group values together:

We might choose to group data together according to department, or by type.

Grouping By Axis Labels

Let's choose Dept as the X Field for Dundas Chart, and Value for Y. In Dundas Chart, strings (text) cannot be used as true X values since they cannot represent a linear numeric or time scale, but they are used as axis labels if you choose a string field as your X value. To group data together, for all values in each department for example, use the GroupByAxisLabels() method in code. Here is an example that groups data in all series and sums up the grouped values:

C#

chartObj.DataManipulator.GroupByAxisLabel("SUM", "*");

VisualBasic.NET

chartObj.DataManipulator.GroupByAxisLabel("SUM", "*")

Grouping By Interval

If we choose Type as the X Field for Dundas Chart, with Value as Y, we can group the values together by type if we group by interval. For a numeric field, use some numeric interval. Your data should be sorted in ascending order by X values if you are grouping data in this way (see this support site article for tips). In the sample dataset above, types are all whole numbers so we can group by an interval of 1:

C#

chartObj.DataManipulator.Group("SUM", 1, IntervalType.Number, "*");

VisualBasic.NET

chartObj.DataManipulator.Group("SUM", 1, IntervalType.Number, "*")

For date/time fields, you can choose interval types such as year, month, day, hour, and so on.

Documentation

For full details on data grouping including all formulas available, see the article "Grouping Data" in the online help.

PoorExcellent