报表统计(八) 访问数据库 Position

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.BackColor = Color.Azure;
26             Chart1.ChartAreas[0].AxisX.LineWidth = 3;
27             Chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Red;
28             Chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Red;
29             Chart1.ChartAreas[0].AxisY.LineWidth = 1;
30             Chart1.ChartAreas[0].Position.X = 2;
31             Chart1.ChartAreas[0].Position.Y = 2;
32             Chart1.ChartAreas[0].Position.Height = 98;
33             Chart1.ChartAreas[0].Position.Width = 98;
34             Chart1.DataSource = GetTempData();
35             Series s1 = new Series();
36             s1.IsValueShownAsLabel = true;
37             s1.ChartType = SeriesChartType.Line;
38             s1.MarkerStyle = MarkerStyle.Circle;
39             s1.MarkerSize = 6;
40             Chart1.Series.Add(s1);
41             Series s2 = new Series();
42             s2.ChartType = SeriesChartType.Line;
43             s2.MarkerStyle = MarkerStyle.Cross;
44            
45             s2.MarkerSize = 6;
46             s2.IsValueShownAsLabel = true;
47             Chart1.Series.Add(s2);
48             Legend l = new Legend();
49             l.Docking = Docking.Right;
50             l.Alignment = System.Drawing.StringAlignment.Center;
51             l.LegendStyle = LegendStyle.Column;
52             l.BackColor = Color.LightGoldenrodYellow;
53             l.Position.X = 86;
54             l.Position.Y = 5;
55             l.Position.Height = 20;
56             l.Position.Width = 12;
57             Chart1.Legends.Add(l);
58             Legend l2 = new Legend();
59             l2.Docking = Docking.Bottom;
60             l2.Alignment = System.Drawing.StringAlignment.Center;
61             l2.LegendStyle = LegendStyle.Row;
62             Chart1.Legends.Add(l2);
63             Legend l1 = new Legend();
64             l1.LegendStyle = LegendStyle.Row;
65             l1.Docking = Docking.Bottom;
66             l1.Alignment = System.Drawing.StringAlignment.Center;
67             Chart1.Legends.Add(l1);
68             Chart1.Series[0].ChartType = SeriesChartType.Line;
69             Chart1.Series[0].XValueMember = "Worker";
70             Chart1.Series[0].YValueMembers = "ProductPrice";
71             Chart1.Series[0].LegendText = "日收入";
72             Chart1.Series[0].ToolTip = "#VALX\t#VALY";
73             Chart1.Series[1].XValueMember = "Worker";
74             Chart1.Series[1].YValueMembers = "YearPrice";
75             Chart1.Series[1].LegendText = "年收入";
76             Chart1.Series[2].XValueMember = "Worker";
77             Chart1.Series[2].YValueMembers = "MonthPrice";
78             Chart1.Series[2].LegendText = "月收入";
79             Chart1.DataBind();
80         }
81     }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值