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

    View Code
     1 public partial class Chartdb3 : System.Web.UI.Page
     2     {
     3         protected void Page_Load(object sender, EventArgs e)
     4         {
     5             if (!IsPostBack)
     6             {
     7                 CreateTempChart();
     8             }
     9         }
    10         public DataTable GetTempData()
    11         {
    12             SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DEMO;Integrated Security=True");
    13             string strSql = "SELECT * FROM ChartDB";
    14             SqlDataAdapter da = new SqlDataAdapter(strSql, con);
    15             DataSet ds = new DataSet();
    16             da.Fill(ds);
    17             if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
    18             {
    19                 return new DataTable();
    20             }
    21             return ds.Tables[0];
    22         }
    23         public void CreateTempChart()
    24         {
    25             DataTable dt = GetTempData();
    26             Chart1.Width = 600;
    27             Chart1.Height = 400;
    28             Chart1.ChartAreas[0].AxisY.Title = "销售收入";
    29             Chart1.ChartAreas[0].AxisX.Title = "销售人员";
    30             Series s1 = new Series();
    31             s1.ChartType = SeriesChartType.Line;
    32             s1.MarkerStyle = MarkerStyle.Triangle;
    33             s1.MarkerSize = 6;
    34             s1.Color = Color.Green;
    35             s1.IsVisibleInLegend = true;
    36             Chart1.Series.Add(s1);
    37             Series s2 = new Series();
    38             s2.ChartType = SeriesChartType.Line;
    39             s2.MarkerStyle = MarkerStyle.Square;
    40             s2.MarkerSize = 6;
    41             s2.IsVisibleInLegend = true;
    42             s2.Color = Color.Yellow;
    43             Chart1.Series.Add(s2);
    44             Series s3 = new Series();
    45             s3.Color = Color.Tomato;
    46             s3.ChartType = SeriesChartType.Line;
    47             s3.MarkerSize = 6;
    48             s3.MarkerStyle = MarkerStyle.Diamond;
    49             s3.IsVisibleInLegend = true;
    50             Chart1.Series.Add(s3);
    51             for (int i = 0; i < 3; i++)
    52             {
    53                 Legend l = new Legend();
    54                 l.Docking = Docking.Bottom;
    55                 l.LegendStyle = LegendStyle.Row;
    56                 l.Alignment = StringAlignment.Center;
    57                 this.Chart1.Legends.Add(l);
    58             }
    59             for (int i = 0; i < dt.Rows.Count; i++)
    60             {
    61                 this.Chart1.Series[0].Points.AddXY(dt.Rows[i]["Worker"].ToString(), dt.Rows[i]["ProductPrice"].ToString());
    62                 Chart1.Series[0].ToolTip = "销售人员:\t#VALX\n收入:\t#VALY";
    63                 this.Chart1.Series[1].Points.AddXY(dt.Rows[i]["Worker"].ToString(), dt.Rows[i]["YearPrice"].ToString());
    64                 Chart1.Series[1].ToolTip = "销售人员:\t#VALX\n年收入:\t#VALY";
    65                 this.Chart1.Series[2].Points.AddXY(dt.Rows[i]["Worker"].ToString(), dt.Rows[i]["MonthPrice"].ToString());
    66                 Chart1.Series[2].ToolTip = "销售人员:\t#VALX\n月收入:\t#VALY";
    67             }
    68             Chart1.Series[0].LegendText = "收入";
    69             Chart1.Series[1].LegendText = "年收入";
    70             Chart1.Series[2].LegendText = "月收入";
    71         }
    72     }
    怀揣着一点点梦想的年轻人
    相信技术和创新的力量
    喜欢快速反应的工作节奏
  • 相关阅读:
    CodeForcesGym 100517B Bubble Sort
    CodeForcesGym 100517H Hentium Scheduling
    BZOJ 1208: [HNOI2004]宠物收养所
    BZOJ 1503: [NOI2004]郁闷的出纳员
    BZOJ 1588: [HNOI2002]营业额统计
    sublime 3 user Settings
    sublime 3 注册码
    Why does this json4s code work in the scala repl but fail to compile?
    cat 显示指定行
    Spark Kill Application
  • 原文地址:https://www.cnblogs.com/hfliyi/p/2727454.html
Copyright © 2011-2022 走看看