My first rubyforge project is called Ambling: a rails plugin that makes it easy to generate XML for the excellent Amcharts.
Instead of having to use Builder to generate the XML, you can do something like this in your controller to generate the data XML:
def pie_data
chart = Ambling::Data::Pie.new
FavoriteColor.count(:color, :group => :color).each do |data|
chart.slices << Ambling::Data::Slice.new(data.last, :title => data.first,
:url => favorite_colors_path(:color => data.first))
end
render :xml => chart.to_xml
end
And then in your view, embed the flash and customize the settings:
<%=
ambling_chart(:pie, :data_file => url_for(:action => 'pie_data'),
:id => 'pie_data', :width => 290, :height => 200,
:chart_settings => Ambling::Pie::Settings.new({
:pie => {
:x => 110,
:y => 110,
:radius => 80,
:colors => '#B40000,#F7941D,#0265AC',
:outline_color => '#000000',
:outline_alpha => 50,
},
:animation => {
:pull_out_on_click => false,
},
:data_labels => {
:show => cdata_section("<b>{value}</b>"), :radius => -30,
},
:legend => {
:enabled => true, :x => 195, :y => 20, :width => 100, :text_color => '#000',
:max_columns => 1, :spacing => 2, :text_size => 10,
:key => {:size => 10}
},
:labels => {
:label =>
{:x => 40, :y => 5, :text => cdata_section("<b>Favorite Colors</b>"),
:text_size => 16, :text_color => '#0265AC'},
}
}).to_xml) do
content_tag('p', "To see this page properly, you need to upgrade your Flash Player")
end
%>
Changing a hash on the fly in the view is much easier for me than changing XML, even using builder.
Thanks to the Ziya rails plugin for inspiration.