如何自定义ASP.Net图表

时间:2012-01-10 09:50:09

标签: asp.net

为我的应用程序创建ASP.NET报告。 我希望我的图形的X-AXIS以这种格式显示Timeperiod:例如 1990-2000,2000-2010,2010-2020等。

protected void Page_Load(object sender, EventArgs e)
{
    SqlConnection DBconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString2"].ToString());
    SqlCommand sqlCmd = new SqlCommand("select YEAR(ValidityFrom) as SpecYear,COUNT(DocumentTypeID) as Total From Document WHERE ValidityFrom is not null AND DocumentTypeID = 1 Group by YEAR(ValidityFrom)", DBconnection);

    SqlDataReader reader;
    try
    {
        DBconnection.Open();
        reader = sqlCmd.ExecuteReader();

        while (reader.Read())
        {
            SumID.Series["summery-id"].Points.AddXY(reader["SpecYear"], reader["Total"]);
        }
        reader.Close();

    }
    catch (SqlException err)
    {
        for (int i = 0; i < err.Errors.Count; i++)
        {
            lblErrorMessage.Text = ("Message: " + err.Errors[i].Message + "\n" +
            "LineNumber: " + err.Errors[i].LineNumber + "\n" +
            "Error-Code: " + err.ErrorCode.ToString() + "\n" +
            "Or Connection To server  Fail");

        }
    }
    catch (NullReferenceException err)
    {
        lblErrorMessage.Text = ("Error:" + err.Message + "\n" +
               "Source :" + err.Source +
               "Method:" + err.TargetSite);

    }
    catch (Exception err)
    {

        lblErrorMessage.Text = "Error Reading Data " + err.Message;

    }
    finally
    {
        DBconnection.Close();
    }

0 个答案:

没有答案