How to Add the RadChart via Stored Procedure Execute

Thread is closed for posting
4 posts, 0 answers
  1. Hiralkumar
    Hiralkumar avatar
    3 posts
    Member since:
    Oct 2012

    Posted 19 May 2013 Link to this post

    I have a Give Below Code for
    webchart.dll

    but i want same thing do in the RadChart
    
    
    
    ColumnChart c = new ColumnChart();
            c.MaxColumnWidth = 20;
            c.Fill.Color = Color.Black;
            c.Fill.ForeColor = Color.Blue;
            c.Fill.Type = InteriorType.Hatch;
            c.Fill.HatchStyle = HatchStyle.Cross;
            c.Legend = "Date/Bill";
            SqlConnection conn = new SqlConnection(@"Data Source=.\SQL2005;Initial Catalog=OrderProcessAutomation;Persist Security Info=True;User ID=sa;Password=123456");
            conn.Open();
            string qry = "Rpt_DailyBillTrend";
            SqlCommand cmd = new SqlCommand(qry, conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@FromDate", txtFromDate.Text);
            cmd.Parameters.AddWithValue("@ToDate", txtToDate.Text);
            c.DataSource = cmd.ExecuteReader();
            c.DataXValueField = "Date";
            c.DataYValueField = "BillCount";
            c.DataBind();
            conn.Close();
            Chart1.Charts.Add(c);
            Chart1.Charts.Add(new LineChart(c.Data, Color.Black));
            Chart1.RedrawChart();
    now how to do .. plzz help me out from this thing.. how to do with the radChart no external DataSource Wizard all things by the Coding only how to do
  2. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 23 May 2013 Link to this post

    Hi Hiralkumar,

    You can use RadChart in code-behind like this:
    SqlConnection conn = new SqlConnection(@"Data Source=.\SQL2005;Initial Catalog=OrderProcessAutomation;Persist Security Info=True;User ID=sa;Password=123456");
                 
    conn.Open();
                 
    string qry = "Rpt_DailyBillTrend";
                 
    SqlCommand cmd = new SqlCommand(qry, conn);
                 
    cmd.CommandType = CommandType.StoredProcedure;
                 
    cmd.Parameters.AddWithValue("@FromDate", txtFromDate.Text);
                 
    cmd.Parameters.AddWithValue("@ToDate", txtToDate.Text);
     
    RadChart radChart1 = new RadChart();
     
    radChart1.DataSource = cmd.ExecuteReader();
     
    var barSeries = new ChartSeries { Type = ChartSeriesType.Bar };
     
    barSeries.DataXColumn = "Date";
     
    barSeries.DataYColumn = "BillCount";
     
    radChart1.Series.Add(barSeries);
     
    radChart1.Skin = "Mac";
     
    radChart1.Legend.TextBlock.Visible = true;
     
    radChart1.Legend.TextBlock.Text = "Date/Bill";
     
    radChart1.DataBind();
     
    Page.Controls.Add(radChart1);

    Please take your time to carefully review our documentation, which you can find on this page.

    I hope this helps.
     
    Regards,
    Petar Kirov
    Telerik
    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
  4. Hiralkumar
    Hiralkumar avatar
    3 posts
    Member since:
    Oct 2012

    Posted 25 May 2013 Link to this post

    error is coming like this...

    The type of column with name  Date is not numeric
  5. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 29 May 2013 Link to this post

    Hi Hiralkumar,

    You are getting this exception because the XValues should be numeric (int, long, double, ...). The ASP.NET RadChart can visualize DateTime information, but you have to first convert it to the OADate format. You can do it like this:
    SqlCommand cmd = new SqlCommand(qry, conn);
    //...
    List<PlotInfo> data;
    using (var reader = cmd.ExecuteReader())
    {
        data = (from IDataRecord dr in reader
           select new PlotInfo
           {
              Date = ((DateTime)dr["Date"]).ToOADate(),
              BillCount = Convert.ToDouble(dr["BillCount"])
           }).ToList();
    }
    radChart1.DataSource = data;
    var barSeries = new ChartSeries { Type = ChartSeriesType.Bar };
    barSeries.DataXColumn = "Date";
    barSeries.DataYColumn = "BillCount";
    //...
     
    public class PlotInfo
    {
        public double Date { get; set; }
        public double BillCount { get; set; }
    }

    Additionally, you will need to tell the control that it is bound to DateTime information, so it can display it appropriately:
    radChart1.PlotArea.XAxis.IsZeroBased = false;
    radChart1.PlotArea.XAxis.Appearance.ValueFormat = ChartValueFormat.ShortDate;


    Regards,
    Petar Kirov
    Telerik
    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.
Back to Top