ROR中图标FusionCharts的用法
作者 杨海军 2011年7月23日
一、安装FusionCharts
将FusionCharts文件夹(Download Package > Code > FusionCharts)拷贝到TimeTrackerApplication的public目录下。
将Download Package > Code > 。
将Download Package > Code > RoR > 。
至此,FusionCharts的安装就已经完成了。
require 'fusioncharts_helper'
include FusionChartsHelper
注意:在某些fusioncharts_helper文件中没有定义get_FC_color方法。如果没有就要自己定义。
二、指定一个到图表的链接
列表1
<td><%= link_to 'Time Chart', {:action=>'view_timesheet_chart',:id=>} %></td>
图1展示的是员工名单页面。在设置完数据库之后,开发者使用Ruby脚手架框架,可以很容易地实现这个功能。我们可以访问“http://yourserver:port/employees”来查看此页面。图1是屏幕部分截图。
图1
点击“Time Chart”链接将会调用employees控制器的view_timesheet_chart动作。列表2列出了它的代码。这个动作的作用是展示选中员工的工时表。它会向Employee模型查询指定员工在“2008-12-01”至“2008-12-07”这段时间的工时表,得到结果之后,渲染“”文件。为了简单起见,在本文中,这个时间范围是固定的。当然,现实世界中,这个时间范围应该是可由员工指定。
三、编写相关方法
编写控制器
列表2
EmployeesController
def view_timesheet_chart
start_date= "2008-12-01"
end_date="2008-12-07"
***@employee_id = params[:id]
employee_details_with_timesheets = (***@employee_id,start_date,end_date)
if(!?)
***@employee_details_with_timesheets =employee_details_with_timesheets[0]
else
***@employee_details_with_timesheets =nil;
end
headers["content-type"]="text/html"
end
这个动作以员工id为参数,它向Employee模型查询指定员工在特定时间范围内的工时表。我们将在Employee模型中加入如列表3所示的函数:
编写模型
列表3
def
(id,start_date, end_date)
conditions=" =? and log_date between ? and ?"
employee_details_with_timesheets=(:all, :include=>'timesheets',:conditions=> [conditions,id,start_date,end_date], :order=>'log_date asc')
return employee_details_with_timesheets
e
fusion图标使用手册 来自淘豆网www.taodocs.com转载请标明出处.