Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6853463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:30:53+00:00 2026-05-27T01:30:53+00:00

I’m using Rails 3 and the Highcharts JS Library for creating charts. And the

  • 0

I’m using Rails 3 and the Highcharts JS Library for creating charts. And the setup works just fine. The only problem is that my data array also includes nil-data. But let me show you the code first. The following snippet defines the data for my Highchart.

data: <%= (30.days.ago.to_date..Date.today).map { |date| Health.total_on_weight(current_user.id, date).to_f}.compact %>

“Health” is the model and “total_on_weight” is a method which is defined in that model:

def self.total_on_weight(id, date)
  where("user_id = ?", id).where("date(date) = ?",date).average(:weight) unless self.nil?
end

As you can see I already tried to create an array which contains only existing data. If there isn’t an entry in my database for the date, it shouldn’t be in the array, but as a matter of fact, it is.

I already tried do delete those entrys with the “compact” method and the “unless” method in my function. But there seems to be another problem which I can’t wrap my head around.

If anybody could explain to me why the nil-entries are still in my array or would have an sollution I would be very thankful.

OK, I narrowed the problem down:

If i leave the “to_f” in the function, as it now is, compact can’t erase the missing values because they are not nil, but 0. And the array looks like this:

[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 100.0, 100.0, 100.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 90.0]

Then, if I leave out the “to_f”, the “compact” function can succesfully delete the missing values, which gives me an array like this:

[100.0, 100.0, 100.0, 90.0]

But the downside of this is, that Highcharts doesn’t has the right dates for my values anymore. It displays them right as I wanted, but the dates just don’t make any sense.

UPDATE:

I managed to fix the problem on my own. The data is now defined by:

data: [
  <% @weights = Health.where("user_id = ?", current_user.id) %>
  <% @weights.each do |weight| %>
    <%= "[Date.UTC(" + weight.date.year.to_s  + ", " + ( weight.date.month - 1 ).to_s  + ", " + weight.date.day.to_s  + ")" + ", " + weight.weight.to_f.round(2).to_s + " ],"%>
  <% end %>
]

This definitely does the trick.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:30:54+00:00Added an answer on May 27, 2026 at 1:30 am

    I managed to fix the problem on my own. The data is now defined by:

    data: [
      <% @weights = Health.where("user_id = ?", current_user.id) %>
      <% @weights.each do |weight| %>
        <%= "[Date.UTC(" + weight.date.year.to_s  + ", " + ( weight.date.month - 1 ).to_s  + ", " + weight.date.day.to_s  + ")" + ", " + weight.weight.to_f.round(2).to_s + " ],"%>
      <% end %>
    ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.