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 = "销售收入";
                    }
                }
    
            }
    怀揣着一点点梦想的年轻人
    相信技术和创新的力量
    喜欢快速反应的工作节奏
  • 相关阅读:
    Ninject依赖注入——构造函数、属性、方法和字段的注入
    轻量级IOC框架:Ninject
    WCF 服务端异常封装
    Tomcat远程调试和加入JMS(转)
    关于与产品相关的品牌、国藉等与产品质量的一些思考(转)
    eclipse及Java常用问题及解决办法汇总
    SourceInsight
    java.util.Timer分析源码了解原理
    WebSocket初探
    JAVA布局管理器
  • 原文地址:https://www.cnblogs.com/hfliyi/p/2727196.html
Copyright © 2011-2022 走看看