This is a migrated thread and some comments may be shown as answers.

Chart labels not displaying until refresh

1 Answer 71 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rhonda
Top achievements
Rank 1
Rhonda asked on 25 Apr 2011, 08:57 PM
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! ");
            }
  }

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 28 Apr 2011, 03:00 PM
Hi Rhonda,

Mixing the chart definition and processing chart is not a good idea and might lead to unexpected problems such as the reported one. Our suggestion is to use the SqlDataSource Component to bind the chart in the report designer and set the respective properties through its property grid.

All the best,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Rhonda
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or