当前位置:编程学习 > C#/ASP.NET >>

UltraChart画图,帮我修改一下代码,急!!!

这是我想要的效果,我已经实现了!不过代码部分太垃圾了!大家帮我改一下!小弟在此谢过了!

我用的是UltraChart控件,我想要的是在某一段之间的人数如:2.0-2.5有10人,2.5-3.0有18人。。。。
因为我这第一次接触这个,所以写的乱七八糟;请大家帮我改一下!下面是cs的代码:
我想能不能这个段数也是查好了显示出来的!大家改好了请发源码上来!谢谢了!
 protected void Page_Load(object sender, EventArgs e)
    {
        chart();
    }

    private void chart()
    {
        string sqlStr1 = "select count(*) from OFB_LeaseInfo where fAvgRent>2 and fAvgRent<2.5";
        string sqlStr2 = "select count(*) from OFB_LeaseInfo where fAvgRent>2.5 and fAvgRent<3";
        string sqlStr3 = "select count(*) from OFB_LeaseInfo where fAvgRent>3 and fAvgRent<3.5 ";
        string sqlStr4 = "select count(*) from OFB_LeaseInfo where fAvgRent>3.5 and fAvgRent<4";
        string sqlStr5 = "select count(*) from OFB_LeaseInfo where fAvgRent>4 and fAvgRent<4.5";
        string sqlStr6 = "select count(*) from OFB_LeaseInfo where fAvgRent>4.5 and fAvgRent<5";
        string sqlStr7 = "select count(*) from OFB_LeaseInfo where fAvgRent>5 and fAvgRent<5.5";
        string sqlStr8 = "select count(*) from OFB_LeaseInfo where fAvgRent>5.5 and fAvgRent<6 ";
        string sqlStr9 = "select count(*) from OFB_LeaseInfo where fAvgRent>6 and fAvgRent<6.5";
        using (SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=COPTV2;Integrated Security=True"))
        {
            con.Open();
            DataSet ds = new DataSet();
            SqlDataAdapter ada1 = new SqlDataAdapter(sqlStr1,con);
            
            ada1.Fill(ds);

            SqlDataAdapter ada2 = new SqlDataAdapter(sqlStr2, con);
            ada2.Fill(ds);

            SqlDataAdapter ada3 = new SqlDataAdapter(sqlStr3, con);
            ada3.Fill(ds);

            SqlDataAdapter ada4 = new SqlDataAdapter(sqlStr4, con);
            ada4.Fill(ds);

            SqlDataAdapter ada5 = new SqlDataAdapter(sqlStr5, con);
            ada5.Fill(ds);

            SqlDataAdapter ada6 = new SqlDataAdapter(sqlStr6, con);
            ada6.Fill(ds);

            SqlDataAdapter ada7 = new SqlDataAdapter(sqlStr7, con);
            ada7.Fill(ds);

            SqlDataAdapter ada8 = new SqlDataAdapter(sqlStr8, con);
            ada8.Fill(ds);

            SqlDataAdapter ada9 = new SqlDataAdapter(sqlStr9, con);
            ada9.Fill(ds);

            DataTable table = new DataTable();
            table.Columns.Add("2.0 - 2.5", typeof(double));
            table.Columns.Add("2.5 - 3.0", typeof(double));
            table.Columns.Add("3.0 - 3.5", typeof(double));
            table.Columns.Add("3.5 - 4.0", typeof(double));
            table.Columns.Add("4.0 - 4.5", typeof(double));
            table.Columns.Add("4.5 - 5.0", typeof(double));
            table.Columns.Add("5.0 - 5.5", typeof(double));
            table.Columns.Add("5.5 - 6.0", typeof(double));
            table.Columns.Add("6.0 - 6.5", typeof(double));
           
            
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                DataRow row = table.NewRow();
                row[i] = ds.Tables[0].Rows[i][0];
                table.Rows.Add(row);
            }
            UltraChart1.DataSource = table;
            UltraChart1.Data.DataBind();
            UltraChart1.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.ColumnChart;
        }
    } --------------------编程问答-------------------- 用存储过程传参数做啊 --------------------编程问答-------------------- 我想要用sql来实现这种效果!有没有办法!谢谢大家了!我想要改好后的源码! --------------------编程问答-------------------- 没有用过,帮你顶一下 --------------------编程问答-------------------- 至少可以改成下面这样,sql有更好,更智能的写法,最好把sql写成储存过程
protected   void   Page_Load(object   sender,   EventArgs   e) 
        { 
                chart(); 
        } 

        private   void   chart() 
        { 
                string   sqlStr   =   "declare @str1 int declare @str2 int "+
" select @str1 =  count(*)   from   OFB_LeaseInfo   where   fAvgRent> 2   and   fAvgRent <2.5 "
" select @str2 =  count(*)   from   OFB_LeaseInfo   where   fAvgRent> 2.5   and   fAvgRent <3 "; 
                sqlStr   += " select @str1 '2.0   -   2.5' ,@str2 '2.5   -   3.0' "; 
                
                using   (SqlConnection   con   =   new   SqlConnection("Data   Source=.;Initial   Catalog=COPTV2;Integrated   Security=True")) 
                { 
                        con.Open(); 
                        DataTable  dt   =   new   DataTable(); 
                        SqlDataAdapter   ada   =   new   SqlDataAdapter(sqlStr,con); 
                        ada1.Fill(dt); 
                        UltraChart1.DataSource   =   dt; 
                        UltraChart1.Data.DataBind(); 
                        UltraChart1.ChartType   =   Infragistics.UltraChart.Shared.Styles.ChartType.ColumnChart; 
                } 
        } --------------------编程问答--------------------  ada1.Fill(dt);   改为 ada.Fill(dt); 我没测试,语句也没写全。    --------------------编程问答-------------------- 提醒一下:縱向的是值,橫向的是字段的名字,所以可以
select TOP(1)
(select   count(*)   from   OFB_LeaseInfo   where   fAvgRent> 2   and   fAvgRent <2.5 )AS '2.0-2.5',
(select   count(*)   from   OFB_LeaseInfo   where   fAvgRent> 2.5   and   fAvgRent <3 ) AS '2.5-3'
from OFB_LeaseInfo    
依次寫下去 --------------------编程问答-------------------- UP!~~~ --------------------编程问答-------------------- 谢谢楼上各位哥哥们!尤其是blackmeit 
可是我想有没有办法把值一次得出来后再进行筛选,
然后显示出来!
--------------------编程问答-------------------- 可以的吧,就是用code处理一下
你可以先全部取出来,然后再用代码来分别取得不同阶段的总数
并存放到一个table中 --------------------编程问答-------------------- 为什么要那样? 得出来后再筛选会影响效率呀 --------------------编程问答-------------------- 一般的方法是把条件传到数据库,在数据库里筛选得到值绑定到前台呀 --------------------编程问答-------------------- 我想能不能这个段数也是查好了显示出来的!

如果想实现这个功能,那就单独对这个段数建表,单独查询。

......

select 段数 from 表A.段数ID=表B.段数ID 

select count(*) from  表A或B  where 段数ID=....

......

--------------------编程问答-------------------- 一般的方法是把条件传到数据库,在数据库里筛选得到值绑定到前台呀
对煤炭的这个想法很感兴趣,可是不知道怎么实现!大家可否帮忙一写代码!尽量用一条sql实现! --------------------编程问答-------------------- 关注........ --------------------编程问答--------------------   for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  {
  DataRow row = table.NewRow();
  row[i] = ds.Tables[0].Rows[i][0];
  table.Rows.Add(row);
  }
你这个for循环好像只是对
SqlDataAdapter ada1 = new SqlDataAdapter(sqlStr1,con);
    
  ada1.Fill(ds);
这句起到作用吧!!!
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,