I'm trying to get highcharts graphs to update automatically from a table. Currently i'm coding each record in one by one as follows:
<script> ... }, series: [{ name: 'Number of Notes By Class Module', data: [<%= Note.where(:subject_type => 'English').count %>, <%= Note.where(:subject_type => 'Geography Class C').count %>, <%= Note.where(:subject_type => 'Maths Class B').count %>] }] }); }); </script>
And in the model notes.rb:
def self.subject_analysis(subject_type) Note.where(:subject_type => English).count if subject_type == :english Note.where(:subject_type => Geography_Class_C).count if subject_type == :Geography_Class_C Note.where(:subject_type => Maths_Class_B).count if subject_type == :Maths_Class_B end
Classmodules schema
t.integer "student_id" t.string "subject" t.datetime "created_at", null: false t.datetime "updated_at", null: false
Clearly this is not ideal. What I want is for the column chart to update automatically when a new record is put in the table. To do this I think I need to use JSON in my controller and pass it to Highcharts. Only I don't know how to do this. Any guidance? Thanks. If more info required I will provide.