zoukankan      html  css  js  c++  java
  • 报表统计(七) 访问数据库 利用XValueMember,YValueMembers绑定

    View Code
     1 public partial class WebForm1 : System.Web.UI.Page
     2     {
     3         protected void Page_Load(object sender, EventArgs e)
     4         {
     5             if (!IsPostBack)
     6             {
     7                 CreateChart();
     8             }
     9         }
    10 
    11         public DataTable GetTempData()
    12         {
    13             string strSql = "SELECT * FROM ChartDB";
    14             SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DEMO;Integrated Security=True");
    15             SqlDataAdapter da = new SqlDataAdapter(strSql, con);
    16             DataSet ds = new DataSet();
    17             da.Fill(ds);
    18             return ds.Tables[0];
    19         }
    20 
    21         public void CreateChart()
    22         {
    23             Chart1.Width = 600;
    24             Chart1.Height = 400;
    25             Chart1.ChartAreas[0].AxisX.LineWidth = 3;
    26             Chart1.ChartAreas[0].AxisY.LineWidth = 3;
    27             Chart1.DataSource = GetTempData();
    28             Series s1 = new Series();
    29             s1.IsValueShownAsLabel = true;
    30             s1.ChartType = SeriesChartType.Line;
    31             s1.MarkerStyle = MarkerStyle.Circle;
    32             s1.MarkerSize = 6;
    33             Chart1.Series.Add(s1);
    34             Series s2 = new Series();
    35             s2.ChartType = SeriesChartType.Line;
    36             s2.MarkerStyle = MarkerStyle.Cross;
    37             s2.MarkerSize = 6;
    38             s2.IsValueShownAsLabel = true;
    39             Chart1.Series.Add(s2);
    40             Legend l = new Legend();
    41             l.Docking = Docking.Bottom;
    42             l.Alignment = System.Drawing.StringAlignment.Center;
    43             l.LegendStyle = LegendStyle.Row;
    44             Chart1.Legends.Add(l);
    45             Legend l2 = new Legend();
    46             l2.Docking = Docking.Bottom;
    47             l2.Alignment = System.Drawing.StringAlignment.Center;
    48             l2.LegendStyle = LegendStyle.Row;
    49             Chart1.Legends.Add(l2);
    50             Legend l1 = new Legend();
    51             l1.LegendStyle = LegendStyle.Row;
    52             l1.Docking = Docking.Bottom;
    53             l1.Alignment = System.Drawing.StringAlignment.Center;
    54             Chart1.Legends.Add(l1);
    55             Chart1.Series[0].ChartType = SeriesChartType.Line;
    56             Chart1.Series[0].XValueMember = "Worker";
    57             Chart1.Series[0].YValueMembers = "ProductPrice";
    58             Chart1.Series[0].LegendText = "日收入";
    59             Chart1.Series[1].XValueMember = "Worker";
    60             Chart1.Series[1].YValueMembers = "YearPrice";
    61             Chart1.Series[1].LegendText = "年收入";
    62             Chart1.Series[2].XValueMember = "Worker";
    63             Chart1.Series[2].YValueMembers = "MonthPrice";
    64             Chart1.Series[2].LegendText = "月收入";
    65             Chart1.DataBind();
    66         }
    67     }
    怀揣着一点点梦想的年轻人
    相信技术和创新的力量
    喜欢快速反应的工作节奏
  • 相关阅读:
    C#--跨线程更新UI--实时显示POST请求传过来的数据
    C#--序列化--JSON和对象互转方法
    C#--winform--Label标签的文字居中
    C#--自定义控件-panel控件(渐变色,文字的绘制)
    C#--自定义控件-开发LED指示灯控件(带闪烁效果)
    艾而特--ModbusTcp通讯测试
    C#--各种方法总结(静态,构造,析构,虚方法,重写方法,抽象,扩展)
    C#--特性的运用试验
    C#--特性基础
    C#--无法将lambda表达式转换为类型‘Delegate’,原因是它不是委托类型
  • 原文地址:https://www.cnblogs.com/hfliyi/p/2728665.html
Copyright © 2011-2022 走看看