ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

C#利用折线图分析产品销售走势

2022-07-16 23:05:19  阅读:189  来源: 互联网

标签:C# int str 折线图 new Font ds 产品销售 con


图形界面

 

 数据

 

 查询效果

 

 代码

   private void button1_Click(object sender, EventArgs e)
        {
            G++;
            DrowFont(this.comboBox1.Text.ToString());
            DrowInfo(this.comboBox1.Text.ToString());
            DrowPic(this.comboBox1.Text.ToString());
        }
        private void DrowFont(string str)
        {
            using(Graphics GrapFont = this.panel1.CreateGraphics())
            {
                GrapFont.Clear(Color.SeaShell);
                Pen p = new Pen(Color.Blue, 2.0f);
                Font f = new Font("华文新魏", 12, FontStyle.Regular);
                Brush b = new SolidBrush(Color.Blue);
                GrapFont.DrawString("『" + str + "』"+"产品销售走势", f, b, 4.0f, 5.0f);
            }
        }
        private void DrowInfo(string str)
        {
            Graphics g = this.groupBox2.CreateGraphics();                    //创建Graphics对象
            g.Clear(Color.SeaShell);                                    //设置背景颜色
            Brush b = new SolidBrush(Color.Blue);                        //创建Brush对象
            Font f = new Font("Arial", 9, FontStyle.Regular);                    //设置Font对象
            using (sqlAda = new SqlDataAdapter("select * from tb_merchandise where t_name='" + str + "' order by t_date", con))
            {
                DataSet ds = new DataSet();                            //创建DataSet对象
                sqlAda.Fill(ds, "tb_09");                                //Fill方法填充对象
                g.DrawString("月份:       " + "价格", f, b, 10.0f, 25.0f);    //绘制标题
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)            //绘制月份及相应的产品价格
                {
                    int month = Convert.ToDateTime(ds.Tables[0].Rows[i][2].ToString()).Month;//获取月份
                    if (month >= 10)
                    {
                        //绘制月份及价格
                        g.DrawString(month + "月: " + "『" + ds.Tables[0].Rows[i][3].ToString() + " 』", f, b, 10.0f, (i + 2) * 25.0f);
                    }
                    else
                    {
                        g.DrawString("0" + month + "月: " + "『" + ds.Tables[0].Rows[i][3].ToString() + " 』", f, b, 10.0f, (i + 2) * 25.0f);
                    }
                }
            }
        }
   private void DrowPic(string str)
        {
            int MaxValue, MinValue;                                //声明变量记录最大值和最小值
            using (cmd = new SqlCommand("select Max(t_price) from tb_merchandise where t_name='" + str + "'", con))
            {
                con.Open();                                        //打开数据库连接
                MaxValue = Convert.ToInt16(cmd.ExecuteScalar());            //获取最大值
                con.Close();                                        //关闭数据库连接
            }
            using (cmd = new SqlCommand("select Min(t_price) from tb_merchandise where t_name='" + str + "'", con))
            {
                con.Open();                                        //打开数据库连接
                MinValue = Convert.ToInt16(cmd.ExecuteScalar());            //获取最小值
                con.Close();                                        //关闭数据库连接
            }
            Graphics g = this.groupBox1.CreateGraphics();                    //创建Graphics对象
            g.Clear(Color.SeaShell);                                    //设置背景
            Brush b = new SolidBrush(Color.Blue);                        //创建Brush对象
            Font f = new Font("Arial", 9, FontStyle.Regular);                //创建Font对象
            Pen p = new Pen(b);                                    //创建Pen对象
            using (sqlAda = new SqlDataAdapter("select * from tb_merchandise where t_name='" + str + "' order by t_date", con))
            {
                ds = new DataSet();                                //实例化DataSet对象
                sqlAda.Fill(ds, "t_date");                                //Fill方法填充对象
                int M = MaxValue / 50 + 1;                            //最大值
                int N = MinValue / 50;                                //最小值
                int T = N;
                for (int i = 0; i <= M - N; i++)
                {
                    g.DrawString(Convert.ToString(T * 50), f, b, 0, 190 - 30 * i);
                    g.DrawLine(p, 30, 200 - 30 * i, 260, 200 - 30 * i);
                    T++;
                }
                int Num = ds.Tables[0].Rows.Count;
                int[] Values = new int[Num];
                for (int C = 0; C < Num; C++)
                {
                    Values[C] = Convert.ToInt32(ds.Tables[0].Rows[C][3].ToString());
                    g.DrawString(Convert.ToDateTime(ds.Tables[0].Rows[C][2].ToString()).Month + "月", f, b, 30 * (C + 1) - 10, 15);
                    g.DrawLine(p, 30 * (C + 1), 200, 30 * (C + 1), 30);
                }
                Point[] P = new Point[Num];
                for (int i = 0; i < Num; i++)
                {
                    P[i].X = 30 * (i + 1);
                    P[i].Y = 290 - Convert.ToInt32(Values[i] / 50f * 30);
                }
                g.DrawLines(p, P);
            }
        }

 

标签:C#,int,str,折线图,new,Font,ds,产品销售,con
来源: https://www.cnblogs.com/for-easy-fast/p/16485514.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有