open flash chart可以生成很多种类的图表
1.获取: public/javascripts/swfobject.js、 public/ open-flash-chart.swf、vendor/ open_flash_chart文件夹,放在你的项目的对应目录下
2.下面代码是生成曲线图:
class TestItController < ApplicationController
def index
@graph = open_flash_chart_object(600,300,"/test_it/graph_code") ##调用所写好的图片生成文件
end
def graph_code
title = Title.new("Multiple Lines") #图表标题
data1 = []
data2 = []
data3 = []
10.times do |x| ##表示横坐标为0到9
data1 << rand(5) + 1 ##第一条线,纵坐标值
data2 << rand(6) + 7 ##第二条线,纵坐标值
data3 << rand(5) + 14 ##第三条线,纵坐标值
end
line_dot = LineDot.new
line_dot.text = "Line Dot"
line_dot.width = 4
line_dot.colour = '#DFC329'
line_dot.dot_size = 5
line_dot.values = data1
line_hollow = LineHollow.new
line_hollow.text = "Line Hollow" ##线的名称
line_hollow.width = 1 ##线的宽度
line_hollow.colour = '#6363AC' ##线的颜色
line_hollow.dot_size = 5 ##线的
line_hollow.values = data2
line = Line.new
line.text = "Line"
line.width = 1
line.colour = '#5E4725'
line.dot_size = 5
line.values = data3
y = YAxis.new
y.set_range(0,20,5) ##纵坐标显示的值(初始值,结束值,间隔)
x_legend = XLegend.new("MY X Legend") ##横坐标单位属性描述
x_legend.set_style('{font-size: 20px; color: #778877}')
y_legend = YLegend.new("MY Y Legend") ##纵坐标属性描述
y_legend.set_style('{font-size: 20px; color: #770077}')
chart =OpenFlashChart.new
chart.set_title(title)
chart.set_x_legend(x_legend)
chart.set_y_legend(y_legend)
chart.y_axis = y
chart.add_element(line_dot)
chart.add_element(line_hollow)
chart.add_element(line)
render :text => chart.to_s
end
end
3.页面代码:
<script type="text/javascript" src="/javascripts/swfobject.js"></script><%= @graph %>
饼图、柱状图等具体见:http://pullmonkey.com/projects/open_flash_chart2/
分享到:
相关推荐
InspiniaAdmin 2.6.1 Rails_Full_Version
agile_web_development_with_rails_3rd_edition.9994652073.pdf
rails_semantic_logger, Rails 语义记录器用语义记录器替换 Rails 缺省记录器 Rails 语义记录器 语义记录器用语义记录器替代 Rails 缺省记录器。http://github.com/rocketjob/rails_semantic_logger文档有关完整文档...
rails_apps_composer, 一个 gem,为 Rails 启动应用程序创建 Rails 应用程序模板 Rails 应用编辑器 Rails 应用程序编辑器 gem 安装一个 命令行 工具来从"食谱"的Collection 组装 Rails 应用程序。"你可以使用 rails_...
inspinia admin 2.5 中的 Rails_Full_Version
复杂Rails系统架构优化
介绍插件,用于对记录进行排序(使用 gem)安装要启用rails_admin_acts_as_list,请将以下内容添加到您的Gemfile : gem 'rails_admin_acts_as_list'gem 'rails_admin' 重要提示: rails_admin_acts_as_list之前必须...
Ruby on Rails Guides_ A Guide to Testing Rails Applications.pdf
RestFul_Rails_Dev_v_0.1 RestFul_Rails_Dev_v_0.1
中文世界唯一一本Rails 4.0.0 + Ruby 2.0.0 的自學書籍
Api-rails5_api_tutorial.zip,了解如何在michael hartl的rails 5教程上构建一个现代api立即在rails应用程序中构建一个api!(Rails 5版本),一个api可以被认为是多个软件设备之间通信的指导手册。例如,api可用于web...
Ruby on Rails Guides_ A Guide to Active Record Associations.pdf
rails_best_practices rails_best_practices是用于检查Rails代码质量的代码度量工具。 它支持以下ORM / ODM: 活动记录 蒙古型 mongomapper 以及以下模板引擎: erb 哈姆 减肥 拉布尔 rails_best_practices...
ruby_on_rails_3_入门教程(中文)
gem 'rails_chart' 然后执行: $ bundle 或者自己安装: $ gem install rails_chart 然后添加到application.js //= require chartjs_init 用法 看法 对于 AJAX 请求: <%= chartjs 'test_chart', ...
weixin_rails_middleware, 微信集成 ruby weixin_rails_middleware for integration weixin.
Rails_Recipes_with_Source_Code
Rails_3_Cheat_Sheets.pdf