从昨天开始收集了很多制作水晶报表的资料,想自学成材,数据都从来效果了,但是就是柱状图的横竖坐标不会定位,发篇博客,有路过的帮帮忙,谢谢了。
以下是cs代码,
1using System;
2using System.Collections;
3using System.Configuration;
4using System.Data;
5using System.Linq;
6using System.Web;
7using System.Web.Security;
8using System.Web.UI;
9using System.Web.UI.HtmlControls;
10using System.Web.UI.WebControls;
11using System.Web.UI.WebControls.WebParts;
12using System.Xml.Linq;
13using System.Data.SqlClient;
14using CrystalDecisions.CrystalReports.Engine;
15using CrystalDecisions.Shared;
16
17public partial class Teacher_fxlr : System.Web.UI.Page
18{
19 string marketid;
20 string marketyear;
21 protected void Page_Load(object sender, EventArgs e)
22 {
23 marketid =Session ["marketid"].ToString ();
24
25 if (!this.IsPostBack)
26 {
27 yearlist();
28 report();
29
30 }
31
32 }
33 protected void report()
34 {
35
36 string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
37 SqlConnection myconn = new SqlConnection(constr);
38 myconn.Open();
39 //marketname--市场名称;marketyear--市场年份;projectname--企业名称,jlr--净利润;xssr--销售收入;
40 //zyl--市场占有率=净利润/销售收入,条件是市场编号marketid等于session传的id值,marketyear等于年份的yearradiobutton的选项值。
41 string sql = "select marketname,marketyear,projectname,jlr,xssr,convert(varchar(10),(jlr*100/xssr))+'%' as zyl from fxlr where marketid='" + marketid + "' and marketyear='" + marketyear + "'";
42 SqlDataAdapter myadr = new SqlDataAdapter(sql, myconn);
43 lrDataSet ds = new lrDataSet();
44 myadr.Fill(ds, "fxlr");
45 ReportDocument myreport = new ReportDocument();
46 string FilePath = Server.MapPath("fxlr.rpt");//映射到当前目录
47
48 if (!myreport.IsLoaded)
49
50 myreport.Load(FilePath);//加载报表
51
52
53 myreport.SetDataSource(ds);
54
55 CrystalReportViewer1.ReportSource = myreport;
56
57 }
58 /// <summary>
59 /// 加载市场年份
60 /// </summary>
61 protected void yearlist()
62 {
63 DataOperate DO = new DataOperate();
64 yearbl.Items.Clear();
65 string sql = "select marketyear from market where id='" + marketid + "'";
66 int yearcount = DO.GetCount(sql);
67 //增加初始年
68 ListItem LI = new ListItem("初始年", "0");
69 yearbl.Items.Add(LI);
70 yearbl.Items[0].Selected = true;
71 for (int i = 1; i <= yearcount; i++)
72 {
73 LI = new ListItem("第" + i + "年", i.ToString());
74 yearbl.Items.Add(LI);
75 }
76
77 }
78 /// <summary>
79 /// 点击查看按钮发生的方法。
80 /// </summary>
81 /// <param name="sender"></param>
82 /// <param name="e"></param>
83 protected void Button1_Click(object sender, EventArgs e)
84 {
85 marketyear=yearbl .SelectedValue;
86 report();
87
88 }
89}
90
2using System.Collections;
3using System.Configuration;
4using System.Data;
5using System.Linq;
6using System.Web;
7using System.Web.Security;
8using System.Web.UI;
9using System.Web.UI.HtmlControls;
10using System.Web.UI.WebControls;
11using System.Web.UI.WebControls.WebParts;
12using System.Xml.Linq;
13using System.Data.SqlClient;
14using CrystalDecisions.CrystalReports.Engine;
15using CrystalDecisions.Shared;
16
17public partial class Teacher_fxlr : System.Web.UI.Page
18{
19 string marketid;
20 string marketyear;
21 protected void Page_Load(object sender, EventArgs e)
22 {
23 marketid =Session ["marketid"].ToString ();
24
25 if (!this.IsPostBack)
26 {
27 yearlist();
28 report();
29
30 }
31
32 }
33 protected void report()
34 {
35
36 string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
37 SqlConnection myconn = new SqlConnection(constr);
38 myconn.Open();
39 //marketname--市场名称;marketyear--市场年份;projectname--企业名称,jlr--净利润;xssr--销售收入;
40 //zyl--市场占有率=净利润/销售收入,条件是市场编号marketid等于session传的id值,marketyear等于年份的yearradiobutton的选项值。
41 string sql = "select marketname,marketyear,projectname,jlr,xssr,convert(varchar(10),(jlr*100/xssr))+'%' as zyl from fxlr where marketid='" + marketid + "' and marketyear='" + marketyear + "'";
42 SqlDataAdapter myadr = new SqlDataAdapter(sql, myconn);
43 lrDataSet ds = new lrDataSet();
44 myadr.Fill(ds, "fxlr");
45 ReportDocument myreport = new ReportDocument();
46 string FilePath = Server.MapPath("fxlr.rpt");//映射到当前目录
47
48 if (!myreport.IsLoaded)
49
50 myreport.Load(FilePath);//加载报表
51
52
53 myreport.SetDataSource(ds);
54
55 CrystalReportViewer1.ReportSource = myreport;
56
57 }
58 /// <summary>
59 /// 加载市场年份
60 /// </summary>
61 protected void yearlist()
62 {
63 DataOperate DO = new DataOperate();
64 yearbl.Items.Clear();
65 string sql = "select marketyear from market where id='" + marketid + "'";
66 int yearcount = DO.GetCount(sql);
67 //增加初始年
68 ListItem LI = new ListItem("初始年", "0");
69 yearbl.Items.Add(LI);
70 yearbl.Items[0].Selected = true;
71 for (int i = 1; i <= yearcount; i++)
72 {
73 LI = new ListItem("第" + i + "年", i.ToString());
74 yearbl.Items.Add(LI);
75 }
76
77 }
78 /// <summary>
79 /// 点击查看按钮发生的方法。
80 /// </summary>
81 /// <param name="sender"></param>
82 /// <param name="e"></param>
83 protected void Button1_Click(object sender, EventArgs e)
84 {
85 marketyear=yearbl .SelectedValue;
86 report();
87
88 }
89}
90
我想要的柱状图是按市场年份点击按钮,出现横坐标为企业的名字,纵坐标为企业的占有率
柱状图的是如下图配置的,但是效果不对,我该怎么配呢?