I have a bar report that is using the NeedDataSource event to set the datasource and labels. On the initial report load the data is correct but the labels are just 1,2,3,... If I refresh the report I get the correct text labels (AUS Approved, AUS Declined,etc...). I have stepped through the code to verify that the dataset is being populated correctly on the initial load. However, when I get to the line of code that sets any of the series elements I get the following error message:"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index". I am trapping for any errors so the report will load with the correct data but no text for the labels. On a refresh I do not get the error and the label appear correctly. Here is the code for my NeedDataSource event:
private
void
chart1_NeedDataSource(
object
sender, EventArgs e)
{
Telerik.Reporting.Processing.Chart procChart = sender
as
Telerik.Reporting.Processing.Chart;
string
sql = @"SELECT COUNT(l.[LookupID])
as
'AUSStatusCnt'
,l.[ClientLookupValue]
as
'AUSStatus'
FROM [AUS] a
INNER JOIN [Organization] o ON a.[OrganizationID]=o.[OrganizationID]
INNER JOIN [Lookup] l ON l.[LookupID] = a.[AUSStatusID]
where a.[AUSID]
in
([dbo].[udf_GetLastAUSStatus](a.[AUSParentID]))
AND a.[OrganizationID]=@OrganizationID AND l.[LookupTypeID]=13
and l.[Active]=1
AND a.[UpdatedByDate] >= DATEADD(d,-90,GETDATE())
GROUP BY l.ClientLookupValue,l.LookupID";
SqlConnection sqlCnn =
new
SqlConnection();
sqlCnn.ConnectionString = ConfigurationManager.ConnectionStrings[
"appConnString"
].ConnectionString;
try
{
DataSet ds =
new
DataSet();
SqlCommand sqlCmd =
new
SqlCommand(sql,sqlCnn);
sqlCmd.Parameters.Add(
"@OrganizationID"
,SqlDbType.Int);
sqlCmd.Parameters[
"@OrganizationID"
].Value =
int
.Parse(Report.ReportParameters[
"OrganizationID"
].Value.ToString());
SqlDataAdapter adapter =
new
SqlDataAdapter(sqlCmd);
adapter.Fill(ds);
procChart.DataSource = ds;
chart1.Series[0].DataLabelsColumn =
"AUSStatusCnt"
;
chart1.Series[0].DataYColumn =
"AUSStatusCnt"
;
chart1.Legend.Visible =
false
;
chart1.PlotArea.XAxis.DataLabelsColumn =
"AUSStatus"
;
chart1.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 0;
chart1.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Color = System.Drawing.Color.DarkSlateBlue;
chart1.PlotArea.Appearance.Dimensions.Margins.Bottom = Telerik.Reporting.Charting.Styles.Unit.Percentage(20);
chart1.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Font =
new
System.Drawing.Font(
"Arial"
, 10,FontStyle.Bold);
adapter.Dispose();
sqlCmd.Dispose();
sqlCnn.Close();
}
catch
(Exception ex)
{
MessageBox.Show(
"Error loading report! "
);
}
}