工作中点滴记录

永远保持学徒心态

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

View Code
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CreateTempChart();
            }
        }
        public void CreateTempChart()
        {
            SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DEMO;Integrated Security=True");
            string strSql = "SELECT productprice,Worker FROM ChartDB";
            SqlCommand cmd = new SqlCommand(strSql, con);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            this.Chart1.Width = 600;
            this.Chart1.Height = 400;
            this.Chart1.ChartAreas[0].AxisX.Title = "销售人员";
            this.Chart1.ChartAreas[0].AxisY.Title = "销售收入";
            this.Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;
            this.Chart1.Series[0].IsValueShownAsLabel = true;
            this.Chart1.Series[0].MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Triangle;
            this.Chart1.Titles.Add("销售状况");
            for (int i = 0; i < this.Chart1.Legends.Count; i++)
            {
                this.Chart1.Legends[i].LegendStyle = System.Web.UI.DataVisualization.Charting.LegendStyle.Row;
                this.Chart1.Legends[i].Docking = System.Web.UI.DataVisualization.Charting.Docking.Bottom;
                this.Chart1.Legends[i].Alignment = System.Drawing.StringAlignment.Center;
            }
            this.Chart1.Series[0].LegendText = "销售";
            this.Chart1.Series[0].ToolTip = "销售:\t#VALX\n收入:\t#VALY";
            this.Chart1.Series[0].Points.DataBindXY(dr, "Worker", dr, "ProductPrice");
            dr.Close();
            con.Close();
            this.Chart1.DataBind();
       
        }

用到DataBindXY方法

posted on 2012-10-17 11:01  梦里故乡  阅读(287)  评论(0编辑  收藏  举报