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 7046343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:38:21+00:00 2026-05-28T02:38:21+00:00

I have a query in Rails that’s extracting 3 data points: data1, data2, and

  • 0

I have a query in Rails that’s extracting 3 data points: data1, data2, and datetime. I need to assemble these into two different 2D arrays for insertion into a graph (Highcharts) such as this: http://jsfiddle.net/RKVgx/

You can see that the data will ultimately be used in the js like:

series: [{
    data: [[6, 540], [7, 540], [7, 1620], [8, 1620]]
},{
    data: [[6, 340], [7, 340], [7, 620], [8, 620]]
}]

By using lazy_high_charts this is pretty straight forward, however I simply need to compose the arrays appropriately for output. What I was thinking was something like this, but I need some help in building the 2D arrays properly for insertion:

readings = ModelName.order("date DESC").select('table_name.data1, table_name.data2, table_name.date').limit(1000).all

# HELP HERE, Need 2D arrays here...
data2_and_time_array = Array.new
data1_and_time_array = Array.new

readings.each do |row|
  # HELP HERE, build place datetime into each for X axis
  data1_and_time_array.push row[:date]
  data2_and_time_array.push row[:date]

  # These are the Y data points in each series
  data1_and_time_array.push row[:data2].to_f
  data2_and_time_array.push row[:data1].to_f

end


f.series(
    :name => 'Data1',
    # Date is X & must be first in each 2D array, I believe
    # in format of: [[X1, Y1], [X2, Y2], ... [Xn, Yn]]
    :data => data1_and_time_array 
)
f.series(
    :name => 'Data2',
    :data => data2_and_time_array
)

If you could provide the appropriate fixes / logic to do this correctly in the example code above, I’d much appreciate it.

  • 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-28T02:38:21+00:00Added an answer on May 28, 2026 at 2:38 am

    Not sure i understand well what you want, but map should do the trick :

    data2_and_time_array = readings.map{|row| [row.date, row.data1.to_f] }
    data1_and_time_array = readings.map{|row| [row.date, row.data2.to_f] }
    

    EDIT :

    you can perform any processing you want inside the block :

    data2_and_time_array = readings.map do{|row| [row.date, row.data1 == -1 ? row.data1.to_f : nil] } 
    

    when performing complex processing, it is encouraged to use the do...end block syntax for a more readable code :

    data2_and_time_array = readings.map do |row| 
      date, data = row.date, row.data1
      data = (data == -1) ? nil : data.to_f
      [date, data]
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I need to write something in Rails 3 that does a query to
I have a (rails 3) application that allows users to query for books. I
I am using in C# MYsql .I have query that works if I run
I've noticed that a few Wordpress blogs have query statistics present in their footer
I have a query that is dynamically built after looking up a field list
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
I have a query that I'm executing from a .NET application to a SQL
I have a query that is currently using a correlated subquery to return the
I have a Rails app that allows users to build up a network structure

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.