Jatinder Singh
2006-Oct-25 17:13 UTC
How to enable Gruff Pie Chart to show data values instead of percentages
I am using Gruff Pie chart for displaying a report of number of items brought for various categories. Now instead of percentages, I want the number of items in each category to be shown against each pie of the chart. Any clues? Regards Jatinder --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
MaverickCoder
2006-Oct-25 18:05 UTC
Re: How to enable Gruff Pie Chart to show data values instead of percentages
What I did to solve this problem was added a attribute @y_axis_formatter to the base class that stores a function to reformat the label. You basically set the attribute to the method you want for the graph you want to modify. The label is in the file base.rb around line 473 and is called marker_label. I used the following syntax. 473: vendor/plugins/gruff/lib/base.rb marker_label = index * increment + @minimum_value.to_f #my changes unless @y_axis_formatter.nil? marker_label= @y_axis_formatter.call(marker_label) end #end @d.fill = @marker_color I use a standard helper to format the label labelFormatter= Proc.new { |label| number_with_precision(label, 0 ) } You will need to include the helper in your controller if you do it this way or write your own formatter method. And finally you just need to specify your formatter before rendering the graph in your controller. graph.y_axis_formatter= labelFormatter Using this technique you can fully customize the labels. Hope this helps. Regards, Chris Burnley Jatinder Singh wrote:> I am using Gruff Pie chart for displaying a report of number of items > brought for various categories. > Now instead of percentages, I want the number of items in each category to > be shown against each pie of the chart. > > Any clues? > > Regards > Jatinder > > ------=_Part_36898_89301.1161796401191 > Content-Type: text/html; charset=ISO-8859-1 > X-Google-AttachSize: 337 > > <div>I am using Gruff Pie chart for displaying a report of number of items brought for various categories.</div> > <div>Now instead of percentages, I want the number of items in each category to be shown against each pie of the chart.</div> > <div> </div> > <div>Any clues?</div> > <div> </div> > <div>Regards</div> > <div>Jatinder</div> > > ------=_Part_36898_89301.1161796401191----~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Jatinder Singh
2006-Oct-25 19:43 UTC
Re: How to enable Gruff Pie Chart to show data values instead of percentages
Lines of code in Base.rb seem to be inside draw_line_markers method. Does the solution given by you work for Pie chart? as I was trying to trace Pie chart instance and it seems draw_line_markers does not get called. Regards, Jatinder On 10/25/06, MaverickCoder <burnley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > What I did to solve this problem was added a attribute > @y_axis_formatter to the base class that stores a function to reformat > the label. You basically set the attribute to the method you want for > the graph you want to modify. The label is in the file base.rb around > line 473 and is called marker_label. I used the following syntax. > > 473: vendor/plugins/gruff/lib/base.rb > marker_label = index * increment + @minimum_value.to_f > > #my changes > unless @y_axis_formatter.nil? > marker_label= @y_axis_formatter.call(marker_label) > end > #end > > @d.fill = @marker_color > > I use a standard helper to format the label > labelFormatter= Proc.new { |label| number_with_precision(label, 0 ) } > > You will need to include the helper in your controller if you do it > this way or write your own formatter method. > And finally you just need to specify your formatter before rendering > the graph in your controller. > graph.y_axis_formatter= labelFormatter > Using this technique you can fully customize the labels. Hope this > helps. > > Regards, > Chris Burnley > > > Jatinder Singh wrote: > > I am using Gruff Pie chart for displaying a report of number of items > > brought for various categories. > > Now instead of percentages, I want the number of items in each category > to > > be shown against each pie of the chart. > > > > Any clues? > > > > Regards > > Jatinder > > > > ------=_Part_36898_89301.1161796401191 > > Content-Type: text/html; charset=ISO-8859-1 > > X-Google-AttachSize: 337 > > > > <div>I am using Gruff Pie chart for displaying a report of number of > items brought for various categories.</div> > > <div>Now instead of percentages, I want the number of items in each > category to be shown against each pie of the chart.</div> > > <div> </div> > > <div>Any clues?</div> > > <div> </div> > > <div>Regards</div> > > <div>Jatinder</div> > > > > ------=_Part_36898_89301.1161796401191-- > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
MaverickCoder
2006-Oct-25 20:47 UTC
Re: How to enable Gruff Pie Chart to show data values instead of percentages
I am not using pie charts. Looking briefly at the code though it looks like the following code is where you would need to make the change in pie.rb. ~ line 40 @d = draw_label(center_x,center_y, half_angle, radius, ((data_row[1][0] / total_sum) * 100).round.to_s + ''% '') I would personally move that calculation of the amount variable out of the call to draw_label to make your changes explicit. You could just as easily provide a callback before the call to do something special with the label. It looks like the draw_label method scales the label appropriately based on what you send it so... Regards, Chris Burnley --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Jatinder Singh
2006-Oct-26 04:23 UTC
Re: How to enable Gruff Pie Chart to show data values instead of percentages
After modifying pie.rb it works fine. But modifying pie.rb would not be the right solution, Is there any alternative? I was thinking of extending pie.rb and overriding method draw of Pie class.or passing a block to the draw method of pie chart which would calcuate the amount to be shown. I dont want to change Gruff library''s code, because then there would be additional maintainability involved. Any clues? Regards, Jatinder On 10/26/06, MaverickCoder <burnley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I am not using pie charts. Looking briefly at the code though it looks > like the following code is where you would need to make the change in > pie.rb. ~ line 40 > > @d = draw_label(center_x,center_y, > half_angle, > radius, > ((data_row[1][0] / total_sum) * 100).round.to_s + > ''% '') > > I would personally move that calculation of the amount variable out of > the call to draw_label to make your changes explicit. You could just as > easily provide a callback before the call to do something special with > the label. It looks like the draw_label method scales the label > appropriately based on what you send it so... > > Regards, > Chris Burnley > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---