0

I have 3 line charts created using Chartkick and for some reason 2 render correctly but on one chart the dates along the horizontal axis render in the reverse order after I push up to Heroku. They render fine locally for all three charts. I have a presentation on this project today (of course) and I would love to get to the bottom of this before I show it to people at 5. the code I have is as follows:

here is a gist of the markup for the broken chart

here is a link to the repo

here is a link to the production site with the broken chart

Broken Chart:

<%= line_chart(
                product.price_log_hash(9),
                {
                  height: "185px", discrete: true, library:
                  {
                    chartArea:
                      {
                        top: 15, left: 35, width: '80%'
                      }, vAxis:
                      {
                        format: '$#,###'
                      },
                    hAxis:
                      {
                        slantedText: true, slantedTextAngle: 90
                      }
                  }
                }   
              )%>

Working chart:

<%= line_chart(product.product.price_log_hash,
                                               {
                                                 height: "150px", discrete: true,     library: 
                                                 {
                                                   chartArea:
                                                     {
                                                       top: 15, left: 35, width: '90%'
                                                     }, vAxis:
                                                     {
                                                       format: '$#,###'
                                                     },
                                                   hAxis:
                                                     {
                                                       slantedText: true, slantedTextAngle: 90
                                                     }
                                                 }
                                               }) %>
ruby_newbie
  • 3,190
  • 3
  • 18
  • 29
  • 1
    You likely need to explicitly `.order("some_col DESC")` your `PriceLog` model. – imderek Aug 06 '14 at 15:49
  • 1
    In [product.rb](https://github.com/massmetrics/app/blob/master/app/models/product.rb#L66) you do not specify how you'd like `PriceLog`s to be ordered. – imderek Aug 06 '14 at 15:50
  • Thank you guys for your help. I guess I didn't think I needed to order them because in rails c on Heroku they were showing in ght correct order. For anyone having similar issues the line that solved it was: def get_price_logs(days = 30) price_logs.order("created_at asc").select do |log| log.created_at >= days.day.ago end end – ruby_newbie Aug 06 '14 at 16:45
  • 1
    Glad to help. You should post that as an answer, and accept it. – imderek Aug 06 '14 at 18:21
  • Ok done. Thanks for the recommendation. I'm still getting the lay of the land here at SO. – ruby_newbie Aug 06 '14 at 18:56

1 Answers1

0

Thank you guys for your help. I guess I didn't think I needed to order them because in rails c on Heroku they were showing in ght correct order. For anyone having similar issues the line that solved it was:

 def get_price_logs(days = 30)
    price_logs.order('created_at asc').select do |log|
      log.created_at >= days.day.ago
    end
  end

Thanks for the help everyone!

ruby_newbie
  • 3,190
  • 3
  • 18
  • 29