views:

249

answers:

3
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.

A: 

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

Ben
here is the example used: http://pullmonkey.com/projects/open_flash_chart2/
Carlos Barbosa
Oh, hadn't found that one. Well, the example is called "test it" and ends with "Let me know how it goes, thanks," so it may not be the best code to put into production.
Ben
A: 

Try

pie.values  = @marcas.collect {|result| PieValue.new(result.ventas.count, result.name)}
Daniel Hoey
A: 

Hi, 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.

Aito