• Chart图表


    这东西挺直观

    封装个类

     public class aaa
        {
            private string name;
    
            public string Name
            {
                get { return name; }
                set { name = value; }
            }
            private int number;
    
            public int Number
            {
                get { return number; }
                set { number = value; }
            }
        }
     private void Form1_Load(object sender, EventArgs e)
            {
                List<aaa> ooo=new List<aaa>();
                SqlConnection conn = new SqlConnection("server=.;database=aaaaa;user=sa;pwd=123");
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "select * from chart";
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        aaa rrr = new aaa();
                        rrr.Name=dr["name"].ToString();
                        rrr.Number = Convert.ToInt32(dr["degree"]);
                        ooo.Add(rrr);
                    }
                }
                cmd.Dispose();
                conn.Close();
                chart1.DataSource=ooo;
                chart1.Series["Series1"].XValueMember ="name";  //Series是个集合[Series1]代表蓝色的柱子,那么就会有[Series2] 设置来源颜色 可以代表其他的
                chart1.Series["Series1"].YValueMembers = "Number";
                
            }

    不多说,这个chart可以添加多个柱状图进行比较,他自己自动获取Y轴最大值所以所比较的两个单位在数值上不要相差很多,当然也可以设计成饼型

    在Series集合里面再添加一个Series,用linq做

    添加linq toSql类

       private void Form1_Load(object sender, EventArgs e)
            {
                DataClasses1DataContext context = new DataClasses1DataContext();
                List<Score> list = context.Score.Take(6).ToList();
                chart1.DataSource = list;
                chart1.Series["Series1"].XValueMember = "sno";
                chart1.Series["Series1"].YValueMembers = "degree";
                chart1.Series["Series2"].XValueMember = "cno";
                chart1.Series["Series2"].YValueMembers = "sno";
            }

  • 相关阅读:
    如何绕过chrome的弹窗拦截机制
    自我介绍
    注册页面的编写
    Roadmap学习目标
    Position
    poj2506 Tiling
    poj3278 Catch That Cow
    poj3624 Charm Bracelet
    钢条切割问题带你彻底理解动态规划
    poj1328 Radar Installation
  • 原文地址:https://www.cnblogs.com/18553325o9o/p/4660265.html
Copyright © 2020-2023  润新知