Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Is there any possible to keep only integers in ASP Ajax chart on y axis please let me know Urgent Iam Struck

C#
public void BindChart()
    {
        string query = string.Format("Select SubjectID,GradeID from dbo.tbl_StudentGrades where StudentID=1001 and TestID=1", "1001");
        DataTable dt = GetData(query);

        string[] x = new string[dt.Rows.Count];
        Decimal[] y = new Decimal[dt.Rows.Count];
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            x[i] = dt.Rows[i][0].ToString();
            y[i] =  Convert.ToInt32(dt.Rows[i][1]);
        }
        LineChart1.Series.Add(new AjaxControlToolkit.LineChartSeries { Data = y });        
        LineChart1.CategoriesAxis = string.Join(",", x);        
        LineChart1.ChartTitle = string.Format("Student Status Subjectwise", "StudentID");
        if (x.Length > 3)
        {
            LineChart1.ChartWidth = (x.Length * 75).ToString();
        }
        LineChart1.Visible = true;
    }

    private static DataTable GetData(string query)
    {
        DataTable dt = new DataTable();
        string constr = "Data Source=xxxxx;Initial Catalog=sss;Persist Security Info=True;User ID=sasasa;Password=asasasas";
        using (SqlConnection con = new SqlConnection(constr))
        {
            using (SqlCommand cmd = new SqlCommand(query))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter())
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = con;
                    sda.SelectCommand = cmd;
                    sda.Fill(dt);
                }
            }
            return dt;
        }
    }
Posted
Updated 28-Sep-15 20:05pm
v3
Comments
Patrice T 29-Sep-15 1:10am    
Yes, probably

What have you done ? where are you stuck ?
Nagarjun558 29-Sep-15 1:26am    
Hello ppolymorphe only decimal values are comming actually I need as 1,2,3,4,5,6 but it is comming as 0.6,1.2,2.5....
Patrice T 29-Sep-15 1:33am    
WHAT IS YOUR CODE ?
Nagarjun558 29-Sep-15 2:02am    
public void BindChart()
{
string query = string.Format("Select SubjectID,GradeID from dbo.tbl_StudentGrades where StudentID=1001 and TestID=1", "1001");
DataTable dt = GetData(query);

string[] x = new string[dt.Rows.Count];
Decimal[] y = new Decimal[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
x[i] = dt.Rows[i][0].ToString();
y[i] = Convert.ToInt32(dt.Rows[i][1]);
}
LineChart1.Series.Add(new AjaxControlToolkit.LineChartSeries { Data = y });
LineChart1.CategoriesAxis = string.Join(",", x);
LineChart1.ChartTitle = string.Format("Student Status Subjectwise", "StudentID");
if (x.Length > 3)
{
LineChart1.ChartWidth = (x.Length * 75).ToString();
}
LineChart1.Visible = true;
}

private static DataTable GetData(string query)
{
DataTable dt = new DataTable();
string constr = "Data Source=xxxxx;Initial Catalog=sss;Persist Security Info=True;User ID=sasasa;Password=asasasas";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
}
}
return dt;
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900