Cast conversion problem in Charts

Thread is closed for posting
2 posts, 0 answers
  1. Ramya
    Ramya avatar
    1 posts
    Member since:
    Dec 2011

    Posted 02 Dec 2011 Link to this post

    Hi
    currently i'm designing reports using Telerik Reporting in layered architecture.every method  related to this  report returns List collections.
    But I'm using Datatables in reports,so that i encounterd this error ,
    Unable to cast object of type 'System.Collections.Generic.List`1[LAEMIV3.Business.Entities._00001.User]' to type 'System.Data.DataTable'.
    can u give me a sample for how to design a chart using grouping in telerik reporting.

     

     

    private void groupHeaderSection1_ItemDataBinding(object sender, EventArgs e)

    {

    users = userProcess.getSalaryDetails(); 

    //seriesMapping.ItemMappings.Add(new ItemMapping("Salary", DataPointMember.YValue, ChartAggregateFunction.Sum));  

    Telerik.Reporting.Processing.

    GroupSection GroupHeaderSection = (Telerik.Reporting.Processing.GroupSection)sender;

     Telerik.Reporting.Processing.Report report = GroupHeaderSection.Report;

     //var group = "jan";

     var group = GroupHeaderSection.DataObject["Month"];  

    string StrExp = null;  

    StrExp = " Month =' " + group + "' ";  

    DataTable table = (DataTable)report.DataSource; 

    DataRow[] rows = table.Select(string.Format("Month", group)); 

    string ChartTitle = null;  

    string XLable = null;  

    string YLable = null;  

    chart1.ChartTitle.Appearance.Position.AlignedPosition = Telerik.Reporting.Charting.Styles.AlignedPositions.Top; 

    Telerik.Reporting.Processing.Chart HourChart = (Telerik.Reporting.Processing.Chart)GroupHeaderSection.ChildElements.Find("chart1", true)[0];  

    //Telerik.Reporting.Processing.Chart HourChart = GroupHeaderSection.ChildElements.Find("Chart_Standard_Email_HourlyProd", true)(0); 

    Telerik.Reporting.

    Chart ChartDef = (Telerik.Reporting.Chart)HourChart.ItemDefinition; 

    ChartDef.Series.Clear(); 

    // DataRow drrow = default(DataRow);  

    chart1.PlotArea.XAxis.Appearance.ValueFormat = Telerik.Reporting.Charting.Styles.

    ChartValueFormat.General;

     

    chart1.PlotArea.XAxis.Appearance.ValueFormat = Telerik.Reporting.Charting.Styles.

     

    ChartValueFormat.General;

     

    ChartDef.PlotArea.XAxis.Clear();

    ChartDef.PlotArea.XAxis.AutoScale =

     

    false;

     

    XLable =

     

    "Month";

     

    YLable =

     

    "Salary";

     

    chart1.PlotArea.XAxis.AxisLabel.TextBlock.Text = XLable;

    chart1.PlotArea.XAxis.AxisLabel.Visible =

     

    true;

     

    chart1.PlotArea.YAxis.AxisLabel.TextBlock.Text = YLable;

    chart1.PlotArea.YAxis.AxisLabel.Visible =

     

    true;

     

     

    Telerik.Reporting.Charting.

     

    ChartSeriesItem SeriesItem = new Telerik.Reporting.Charting.ChartSeriesItem();

     

    Telerik.Reporting.Charting.

     

    ChartSeriesItem SeriesItem1 = new Telerik.Reporting.Charting.ChartSeriesItem();

     

     

     

     

    users = userProcess.getSalaryDetails();

     

     

    foreach (DataRow row in rows)

     

    {

     

     

    //Telerik.Reporting.Charting.ChartSeriesItem SeriesItem = new Telerik.Reporting.Charting.ChartSeriesItem();

     

     

     

    //Telerik.Reporting.Charting.ChartSeriesItem SeriesItem1 = new Telerik.Reporting.Charting.ChartSeriesItem();

     

    SeriesItem.YValue =

     

    Convert.ToDouble(row["Month"]);

     

    ChartSeries.Items.Add(SeriesItem);

    ChartSeries.Name =

     

    "Month";

     

    SeriesItem.Label.TextBlock.Appearance.TextProperties.Color = System.Drawing.

     

    Color.Black;

     

    ChartSeries.Appearance.FillStyle.MainColor =

     

    Color.Green;

     

    ChartSeries.Appearance.FillStyle.SecondColor =

     

    Color.Green;

     

    ChartSeries.Type = Telerik.Reporting.Charting.

     

    ChartSeriesType.Bar;

     

    SeriesItem1.YValue =

     

    Convert.ToDouble(row["Salary"]);

     

    ChartSeries1.Items.Add(SeriesItem1);

    ChartSeries1.Name =

     

    "Salary";

     

    SeriesItem1.Label.TextBlock.Appearance.TextProperties.Color = System.Drawing.

     

    Color.Black;

     

    ChartSeries1.Appearance.FillStyle.MainColor =

     

    Color.DarkRed;

     

    ChartSeries1.Appearance.FillStyle.SecondColor =

     

    Color.DarkRed;

     

    ChartSeries1.Type = Telerik.Reporting.Charting.

     

    ChartSeriesType.Bar;

     

    }

    ChartDef.PlotArea.XAxis.AutoScale =

     

    false;

     

    ChartDef.PlotArea.XAxis.AutoShrink =

     

    false;

     

    chart1.PlotArea.YAxis.AxisMode = Telerik.Reporting.Charting.

     

    ChartYAxisMode.Extended;

     

    ChartDef.Series.AddRange(

     

    new Telerik.Reporting.Charting.ChartSeries[] { ChartSeries });

     

    ChartDef.Series.AddRange(

     

    new Telerik.Reporting.Charting.ChartSeries[] { ChartSeries1 });

     

    }

  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 06 Dec 2011 Link to this post

    Hello Ramya,

    Although you can create a chart based on the group data programmatically, there is an easier way to accomplish this through Bindings. See the following links for implementation details on both approaches:
    Kind regards,
    Steve
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top