ruby - Rubyvis in Rails -
i making project using rails , need make charts thinking using rubyvis.
if have following code in controller:
require 'rubyvis' vis = rubyvis::panel.new width 150 height 150 bar data [1, 1.2, 1.7, 1.5, 0.7, 0.3] width 20 height {|d| d * 80} bottom(0) left {index * 25} end end vis.render puts vis.to_svg
how should put output in view?
generating svg file @ runtime wish display in rendered view not should done within controller.
instead, create new method in app/helpers/application_helper.rb
or helper specific controller action.
require "rubyvis" class applicationhelper def some_method vis = rubyvis::panel.new width 150 height 150 bar data [1, 1.2, 1.7, 1.5, 0.7, 0.3] width 20 height {|d| d * 80} bottom(0) left {index * 25} end end vis.render vis.to_svg end end
and in view can call following wherever wish dump svg data.
<%= some_method %>
Comments
Post a Comment