Reputation: 1432
def reparto_de_ventas_por_marca
#obtener los montos de las ventas en el periodo comprendido y sumarlas
@ventas = Venta.find(:all)
@marcas = Marca.find(:all)
title = Title.new("Ingresos de este mes: #{@total}")
pie = Pie.new
pie.start_angle = 35
pie.animate = true
pie.tooltip = '#val# de #total#<br>#percent# de 100%'
pie.colours = ["#245a9c", "#fff"]
pie.values = [
@marcas.each do |result|
PieValue.new(result.ventas.count, result.name)
end
]
chart = OpenFlashChart.new
chart.title = title
chart.add_element(pie)
chart.x_axis = nil
render :text => chart.to_s
end
It just doesn't works i need to get the values to create a graph with flash chart.
any help will be appreciated.
Upvotes: 0
Views: 675
Reputation: 6872
check if your values are floats/decimals. If your language is spanish, it is possible that your decimal separator is a 'comma', and that brokes the json structure. One solution could be to set your locale to english. Another soultion is to round your values to integer... I hope it helps you.
Regards.
Upvotes: 0
Reputation: 16
Try
pie.values = @marcas.collect {|result| PieValue.new(result.ventas.count, result.name)}
Upvotes: 0
Reputation: 6965
I'm not sure which Open Flash Chart plugin you're using, but it looks to me like they both use the method #render
, not #to_s
to render the chart.
Here are the examples: http://pullmonkey.com/projects/open_flash_chart/view_source_code/pie http://rails-open-flash-chart-plugin.googlecode.com/svn/trunk/lib/open_flash_chart.rb
Upvotes: 0