by Al Beecy
April 15, 2009
Recently I was getting an error message from a Dundas chart saying that "Data series for the Stacked Area chart can not have a different number of data points." while using the DataBindCrossTab() method. I was using a stacked area chart, but the error or a similar one occurs on a number of different stacked chart types.
Turns out that after databinding, but before setting the chart type, you must call the AlignDataPointsByAxisLabel() method as shown:
//databind
Chart1.DataBindCrossTab(
new DataView(myDataTable),
"seriesGroupByField",
"xField",
"yField",
string.Empty);
//create fake data points if needed
Chart1.AlignDataPointsByAxisLabel();
//set chart type
foreach (Series series in Chart1.Series)
{
series.Type = SeriesChartType.StackedArea;
}
What the AlignDataPointsByAxisLabel() method does is fake up data points as needed so that all series have the same number.