如何在ASP.NET图表的同一轴上显示2组数据 [英] How to display 2 sets of data on the same axis of ASP.NET chart

查看:152
本文介绍了如何在ASP.NET图表的同一轴上显示2组数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在图表的同一轴上显示2组数据。在X轴上,我将显示UserID,在Y轴上,将显示用户检查的所有纸张的平均标记。但是我还想显示每个用户平均得出的小册子数量。怎么做呢?我希望图表看起来像这样

I want to display 2 sets of data on the same axis of a chart . On the X axis I would be displaying the UserID and on Y axis the Avg marks of all papers checked by the user. But i also want to display the number of booklets for which the avg has been derived for each user . How to go about it? I want the chart to look like this

其中,除平均数外,数字是特定用户检查的论文数。

Where The numbers besides the avgs are the number of papers checked by particular user.

到目前为止,我有这个:

Till now I have this:

     private void Bindchart()
    {

        string msg = string.Empty;
        try
        {
            connection.Open();
            SqlCommand cmd = new SqlCommand("select Teacher_code, sum(Total_marks)/ count(*) as avgmarks , COUNT(*) as no_of_copies from " + connection.Database + "_transctn where sub_code='" + DropDown_Subjects.SelectedValue + "' and Teacher_code!='' group by Teacher_code", connection);

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);

            DataTable ChartData = ds.Tables[0];

            //storing total rows count to loop on each Record  
            string[] XPointMember = new string[ChartData.Rows.Count];


            decimal[] YPointMember = new decimal[ChartData.Rows.Count];

            int totalrows = ChartData.Rows.Count;

            if (totalrows > 0)
            {
                for (int count = 0; count < ChartData.Rows.Count; count++)
                {
                    //storing Values for X axis  
                    XPointMember[count] = ChartData.Rows[count]["Teacher_code"].ToString();
                    //storing values for Y Axis  
                    YPointMember[count] = Convert.ToDecimal(ChartData.Rows[count]["avgmarks"]);




                }
                //binding chart control  
                Chart1.Series[0].Points.DataBindXY(XPointMember, YPointMember);

                //Setting width of line  
                Chart1.Series[0].BorderWidth = 5;
                //setting Chart type   
                Chart1.Series[0].ChartType = SeriesChartType.Column;
                //Chart1.Series[0].ChartType = SeriesChartType.StackedColumn;  

                //Hide or show chart back GridLines  
                Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = true;
                Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = true;

                //Enabled 3D  
                //Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;  
                connection.Close();
            } 
        }


推荐答案

尝试

    protected void Page_Load(object sender, EventArgs e)
    {
        connection.Open();

        SqlCommand cmd = new SqlCommand("Your SQL here.", connection);

        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);

        DataTable ChartData = ds.Tables[0];

        Chart1.Series[0].Points.DataBind(ChartData.DefaultView, "Teacher_code", "avgmarks", "");

        for (int i = 0; i < Chart1.Series[0].Points.Count; i++)
            Chart1.Series[0].Points[i].Label = string.Format("{0:0.00} ({1})", ChartData.Rows[i]["avgmarks"], ChartData.Rows[i]["no_of_copies"]);

        connection.Close();
    }

这篇关于如何在ASP.NET图表的同一轴上显示2组数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆