Highcharts - Rails array includes empty date entries

前端 未结 1 1664
无人共我
无人共我 2021-01-16 08:18

I\'m working on a Rails 3.1.1 app with a dashboard of various line graphs using Highcharts. I implemented the sample code in Railcast 223 (highcharts) -- and everything wor

1条回答
  •  野的像风
    2021-01-16 09:20

    If you want nothing to be graphed but the date to still show up, then change any zeroes to a javascript null. If you want to not graph those days, then you should reject them from the array before output.

    So:

    (3.weeks.ago.to_date..Date.today).map{|date| total=Order.total_on(date).to_f; total.zero? ? "null" : total }.inspect
    

    Or:

    (3.weeks.ago.to_date..Date.today).map{|date| Order.total_on(date).to_f}.reject(&:zero?).inspect
    

    0 讨论(0)
提交回复
热议问题