On Apr 1, 11:29 pm, John Merlino <li...@ruby-forum.com> wrote:
> Hey all,
>
> I am unable to get a highcharts plugin to render a chart in a rails
> application:http://github.com/loudpixel/highcharts-rails
>
> I believe it has something to do with the sql queries to the database
> placed in a ruby array, which the javascript is unable to intepret. This
> is what I have:
>
> def panels
> pass = Student.find_by_sql('SELECT COUNT(*) FROM students WHERE
> student_state = 1')
> fail = Student.find_by_sql('SELECT COUNT(*) FROM students WHERE
> student_state = 2')
>
Are you expecting pass and fail to be numbers? They're not  -
Student.find_by_sql always returns an array of student objects. Sounds
like you might want count.

Fred
> student_data = [
>   {:name => 'Pass', :y => pass},
>   {:name => 'Fail', :y => fail}
> ]
> pie_label_formatter = '
>   function() {
>     if (this.y > 15) return this.point.name;
>   }'
>
> pie_tooltip_formatter = '
>   function() {
>     return "<strong>" + this.point.name + "</strong>: " + this.y + " %";
>   }'
>
> @pie_chart =
>     Highchart.pie({
>     :chart => {
>           :renderTo => "pie-chart-container",
>           :margin => [50, 30, 0, 30]
>         },
>         :plotOptions => {
>           :pie => {
>             :dataLabels => {
>               :formatter => pie_label_formatter,
>               :style => {
>                 :textShadow => '#000000 1px 1px 2px'
>               }
>             }
>           }
>         },
>       :series => [
>             {
>                 :type => 'pie',
>                 :data => student_data
>             }
>         ],
>         :subtitle => {
>           :text => 'April 2010'
>         },
>         :title => {
>           :text => 'Student Status Chart'
>         },
>         :tooltip => {
>           :formatter => pie_tooltip_formatter
>         },
>     })
>
> Note if I put this: :data => student_data.to_json It actually returns a
> json string of my query as text in the browser. Also, if I hard code
> values (e.g. :y => 1), it will render the chart properly. However, any
> database query will not render the chart properly. So I'm not sure
> exactly what the issue is. Any suggestions? Thanks.
> --
> Posted viahttp://www.ruby-forum.com/.

-- 
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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to