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

How to Add the RadChart via Stored Procedure Execute

3 Answers 70 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Hiralkumar
Top achievements
Rank 1
Hiralkumar asked on 19 May 2013, 06:57 AM
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

3 Answers, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 23 May 2013, 06:18 AM
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.
0
Hiralkumar
Top achievements
Rank 1
answered on 25 May 2013, 07:27 PM
error is coming like this...

The type of column with name  Date is not numeric
0
Petar Kirov
Telerik team
answered on 29 May 2013, 06:22 PM
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.
Tags
Chart (Obsolete)
Asked by
Hiralkumar
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Hiralkumar
Top achievements
Rank 1
Share this question
or