Question

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.

Was it helpful?

Solution

Try

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

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top