简体   繁体   中英

Chartkick cannot render API in rails

I'm trying to make a line chart from the API data

[{"Apr 11":{"count":150}},{"Apr 12":{"count":140}},{"Apr 13":{"count":160}}]

I tried doing:

@metrics.each do |data| data.each do |key, value| render json: data(:key).count end end @metrics.each do |data| data.each do |key, value| render json: data(:key).count end end All example in chartkick is rendering Model data. I'm struggling with rendering API data. Can anyone explain me how can I do it?

First build a json then return this one

json_object = @metrics.map do |m|
{ date_value  => { :count => count_value} }
end

render :json => json_object

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM