pullmonkey / open_flash_chart

The ruby on rails plugin for teethgrinder's Open Flash Chart (version 2)

This URL has Read+Write access

open_flash_chart / README
100644 95 lines (69 sloc) 2.023 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
OpenFlashChart Version 2.0.0 11/14/2008
==============
 
1) rails ofc2_test_app
2) cd ofc2_test_app
3) script/plugin install git://github.com/pullmonkey/open_flash_chart.git
4) script/generate controller test_it
 
5) Add the following to the test_it_controller.rb in RAILS_ROOT/app/controllers:
class TestItController < ApplicationController
  
  def index
    respond_to do |wants|
      wants.html {
        @graph = open_flash_chart_object( 600, 300, url_for( :action => 'index', :format => :json ) )
      }
      wants.json {
        chart = OpenFlashChart.new( "MY TITLE" ) do |c|
          c << BarGlass.new( :values => (1..10).sort_by{rand} )
        end
        render :text => chart, :layout => false
      }
    end
  end
 
end
 
6) Add the following to index.html.erb in RAILS_ROOT/app/views/test_it/:
<html>
<head>
  <script type="text/javascript" src="/javascripts/swfobject.js"></script>
</head>
<body>
<%= @graph %>
</body>
</html>
 
7) script/server
8) Let me know how it goes, thanks.
 
 
Example
=======
 
# GOT THIS WORKING JSON wise ... haven't really tested too much further
data = []
 
for i in (0..31)
  data << Math.sin(i * 0.2) * 1.9
end
 
chart = OpenFlashChart::OpenFlashChart.new
chart.title = OpenFlashChart::Title.new(:text => 'Area Chart')
 
area = OpenFlashChart::Area.new
area.width = 2
area.dot_style = OpenFlashChart::HollowDot.new
area.colour = '#838A96'
area.fill = '#E01B49'
area.fill_alpha = 0.4
area.values = data
 
chart.elements = []
chart.elements << area
 
y_axis = OpenFlashChart::YAxis.new
y_axis.min = -2
y_axis.max = 2
y_axis.steps = 2
 
y_axis.labels = nil
 
y_axis.offset = 0
 
x_axis = OpenFlashChart::XAxis.new
x_axis.labels = data
x_axis.steps = 2
 
x_labels = OpenFlashChart::XAxisLables.new
x_labels.steps = 4
x_labels.rotate = 270
 
x_axis.labels = x_labels
 
chart.y_axis = y_axis
chart.x_axis = x_axis
 
puts chart.render
 
 
Example above and more to follow here - http://www.pullmonkey.com/projects/open_flash_chart
 
 
Copyright (c) 2008 PullMonkey, released under the MIT license