Sha256: b22d23cfc843f2254a884d74152d5a2d04f6b85d08bfa23b972fdc4bbe74dcae

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require 'rubygems'
require 'sinatra'
require 'builder'

# require ZiYa gem and helpers
require 'ziya'
require 'ziya/html_helpers'
require 'ziya/yaml_helpers'

# initialize ZiYa environment
configure do
  Ziya.initialize( 
    :log_level  => :debug,
    :themes_dir => File.join( File.dirname(__FILE__), %w[public charts themes] ) )
end

helpers do
  # add ZiYa helpers
  include Ziya::HtmlHelpers::Charts
  include Ziya::YamlHelpers::Charts
  
  # Default chart
  def gen_chart
    chart = Ziya::Charts::Column.new
    chart.add :axis_category_text, %w[2007 2008 2009]
    chart.add :series, 'dogs', [10,20,30]
    chart.add :series, 'cats', [5,15,25]
    chart    
  end
end

# Setup chart and callbacks
get '/' do
  erb :index
end

get '/blee' do
  chart = Ziya::Charts::Line.new
  chart.add :axis_category_text, %w[2007 2008 2009]
  chart.add :series, 'dogs', [ {:value => 10 }, nil, { :value => 30 }]
  chart.add :theme , 'cool_theme'  
  chart.to_xml  
end

# defines a simple column chart
get '/load_chart' do
  gen_chart.to_xml
end

# exact same chart as above but styled
get '/load_themed_chart' do
  chart = gen_chart
  chart.add :theme , 'cool_theme'
  chart.to_xml  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ziya-2.1.6 examples/charts/basic_chart.rb