zoukankan      html  css  js  c++  java
  • 报表统计(三) 访问数据库

    View Code
    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    CreateChartImage();
                }
            }
            public DataTable GetTempData()
            {
                SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DEMO;Integrated Security=True");
                string strSql = "SELECT * FROM ChartDB";
                SqlDataAdapter da = new SqlDataAdapter(strSql, con);
                DataSet ds = new DataSet();
                da.Fill(ds);
                if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
                {
                    return new DataTable();
                }
                return ds.Tables[0];
            }
            public void CreateChartImage()
            {
                DataTable dt = GetTempData();
                this.Chart1.Width = 600;
                this.Chart1.Height = 400;
                this.Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;
                this.Chart1.Series[0].MarkerStyle = MarkerStyle.Circle;
                this.Chart1.Series[0].MarkerSize = 6;
                this.Chart1.Series[0].ToolTip = "销售:\t#VALX\n收入:\t#VALY";
                this.Chart1.Series[0].IsValueShownAsLabel = true;
                this.Chart1.ChartAreas[0].AxisX.Title = "销售";
                this.Chart1.ChartAreas[0].AxisY.Title = "收入";
                this.Chart1.Titles.Add("销售报表");
                for (int i = 0; i < this.Chart1.Legends.Count; i++)
                {
                    this.Chart1.Legends[i].Docking = Docking.Bottom;
                    this.Chart1.Legends[i].Alignment = StringAlignment.Center;
                    this.Chart1.Legends[i].LegendStyle = LegendStyle.Row;
                }
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    this.Chart1.Series[0].Points.AddXY(dt.Rows[i]["Worker"].ToString(), dt.Rows[i]["ProductPrice"].ToString());
                    if (decimal.Parse(dt.Rows[i]["ProductPrice"].ToString()) > 30000)
                    {
                        this.Chart1.Series[0].Points[i].MarkerColor = Color.Red;
                        this.Chart1.Series[0].LegendText = "销售收入";
                    }
                }
    
            }
    怀揣着一点点梦想的年轻人
    相信技术和创新的力量
    喜欢快速反应的工作节奏
  • 相关阅读:
    Redis连接池的介绍和原理
    Golang操作第三方开源Redis库
    Redis的五大数据类型和CRUD操作
    Redis的基本使用
    Redis数据库的基本介绍和安装
    Golang基于TCP协议实现简单的server和client聊天
    Golang反射中的Type和Kind的区别
    Golang中的常量
    Golang对基本数据类型和结构体进行反射
    Vue 使用lodash库减少watch对后台请求压力
  • 原文地址:https://www.cnblogs.com/hfliyi/p/2727196.html
Copyright © 2011-2022 走看看