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 = "销售收入";
                    }
                }
    
            }
    怀揣着一点点梦想的年轻人
    相信技术和创新的力量
    喜欢快速反应的工作节奏
  • 相关阅读:
    PHP filter_input_array() 函数
    pt-query-digest 用法
    [SDOI2017]苹果树
    C# json 转 xml 字符串
    C# json 转 xml 字符串
    C# double 好用的扩展
    C# double 好用的扩展
    win10 uwp 使用 Microsoft.Graph 发送邮件
    win10 uwp 使用 Microsoft.Graph 发送邮件
    Sublime Text 安装中文、英文字体
  • 原文地址:https://www.cnblogs.com/hfliyi/p/2727196.html
Copyright © 2011-2022 走看看