工作中点滴记录

永远保持学徒心态

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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 = "销售收入";
                }
            }

        }
posted on 2012-10-17 09:56  梦里故乡  阅读(340)  评论(0编辑  收藏  举报