在开发项目时用到了visifire图表,参照了jspFire进行了封装,并加入了一些新的属性,改变了一些方法
website中创建Charts文件夹,在该文件夹中添加Visifire.js和SL.Visifire.Charts.xap两个文件
aspx页面代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>图表演示</title> <script src="../Charts/Visifire.js" type="text/javascript"></script> </head> <body> <form id="form1" runat="server"> <div> <asp:Literal ID="ltlVisifire" runat="server"></asp:Literal> </div> </form> </body> </html>
aspx.cs代码
protected void Page_Load(object sender, EventArgs e) { VisifireBind(); } void VisifireBind() { string strYear = "2012"; BLL bll = new BLL(); ltlVisifire.Text = bll.GetRegCountByMonth(strYear); }
bll代码
public string GetRegCountByMonth(string strYear) { if (string.IsNullOrEmpty(strYear)) { strYear = DateTime.Now.Year.ToString(); } DataTable dt = dal.GetRegCountByMonth(strYear); Chart chart = new Chart("../Charts/SL.Visifire.Charts.xap", "../Charts/Visifire.js"); // 创建一个 Chart 实例 chart.Bevel = true; Title title = new Title(); // 创建一个 Title 实例 //title.setEnabled(true); title.Text = "注册商家数量月份统计"; title.FontSize = 14; chart.AddTitle(title); Title titleSub = new Title(); //titleSub.setEnabled(true); titleSub.Text = strYear; chart.AddTitle(titleSub); DataSeries series = new DataSeries(); // 创建一个 图表 series.RenderAs = ChartType.Column; foreach (DataRow dr in dt.Rows) { DataPoint dp = new DataPoint(); // 创建数据结点 dp.YValue = dr["RegCount"].ToString(); dp.AxisXLabel = dr["CreateDate"].ToString(); series.AddDataPoint(dp); } chart.AddSeries(series); return chart.Render(); }
dal层就不贴了