javascript - How to populate chart with data from database? -
i'm following railscast create chart of data. recommends following:
orders.js
jquery ->   morris.line     element: 'orders_chart'     data: $('#orders_chart').data('orders')     xkey: 'purchased_at'     ykeys: ['price', 'shipping_price', 'download_price']     labels: ['total price', 'shipping price', 'download price']     preunits: '$'   and create element in view, table in view fills graph. however, data not $('#orders_chart').data('orders'), rather data directly database table doesn't shown on webpage. how that?
step 1:
set route in routes files give json data:
get '/get_graph_data', to: 'graphs#data_show', as: 'get_graph_data', defaults: {format: 'json'}   step 2:
write controller
class graphscontroller   def data_show     json data   end end   write ajax request
get_graph_data = ->   url = (you can use data-tag url view)   $.ajax     type: 'get'     url: url     datatype: 'json'     success: (json) ->       send_data_to_morris or method change if necessary      
Comments
Post a Comment