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

Aligning Data By Axis Labels

 

Q. Why is my data mixed up when using strings for X-values?

A. When you use a string field for X values in Dundas Chart, your data points are not automatically positioned according to the value of the string. This is because strings are used as "axis labels" and stored in the data point's AxisLabel property, and lets you use the same string along the X axis more than once. This can cause problems, however, if you have multiple series using string X-values and the series are not "aligned" – that is, the various series do not have the same string axis labels in the same order for its data points.

Aligning Data

To resolve this, you need to instruct Dundas Chart to align your data using the axis labels. The chart has a method to use in code: AlignDataPointsByAxisLabel(). This method requires that axis labels be unique within each series. If your strings can repeat within a series, see "Grouping Data" below.


Figure 1: Data points are aligned by their axis labels

[C#]
chartObj.AlignDataPointsByAxisLabel();

[VB.NET]
chartObj.AlignDataPointsByAxisLabel()

If you are using Dundas Chart for SharePoint, you can access our code editor to use this method:

  • In the chart web part's top-right corner, click the drop-down menu and choose Code Editor.
  • In the Event Name drop-down, choose PostApplyData.
  • Paste in code for the appropriate language. (Visual Basic or VB.NET is selected by default.)

Grouping Data

If your data can include the same string more than once in a series and you want to group all of these values as one column, or align them as described above, you first need to group your data points using the axis labels.

[C#]
chartObj.DataManipulator.GroupByAxisLabel("SUM", "*");
chartObj.AlignDataPointsByAxisLabel();

[VB.NET]
chartObj.DataManipulator.GroupByAxisLabel("SUM", "*")
chartObj.AlignDataPointsByAxisLabel()

This example groups the data using the "SUM" formula, and groups all series at once by specifying "*". For more information on grouping, see "Grouping Data" in our documentation.

PoorExcellent