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

  • Home
  • SEARCH
  • 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 8174747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:32:31+00:00 2026-06-06T22:32:31+00:00

I am trying to graph data that I am pulling from an ActiveRecord query

  • 0

I am trying to graph data that I am pulling from an ActiveRecord query in Ruby on Rails. The JavaScript charting library (amcharts) accepts data in the following form:

 var chartData = [{
            date: new Date(2012, 0, 1),
            products: 227
        }, {
            date: new Date(2012, 0, 2),
            products: 371
        }]

How do I parse a date string in the format YYYY-MM-DD and create a JavaScript Date object from the query below? I’ve seen this tutorial but I’m having trouble figuring out how to write a function to correctly parse the json output.

  create_table :products do |t|
        t.date :date
  end

 <% a = Product.select("date(date) as date, count(id) as products").group("date(date)").to_a.to_json %>
  • 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-06-06T22:32:33+00:00Added an answer on June 6, 2026 at 10:32 pm

    Here is the answer that worked for me:

     function parseDate(dateString) {
         // split the string get each field
         var dateArray = dateString.split("-");
         // now lets create a new Date instance, using year, month and day as parameters
         // month count starts with 0, so we have to convert the month number
         var date = new Date(Number(dateArray[0]), Number(dateArray[1]) - 1, Number(dateArray[2]));
         return date;
     }
    
         var array = <%= a.to_json %>;
    
         var array2 = [];
    
         array.forEach(function(element){ 
           array2.push({date: parseDate(element.date), products: element.products});
         });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert the data from a simple object graph into a dictionary.
I am trying to retrieve data from an XML file that is not located
I have a graph that keeps getting dynamically changing data from our server based
I'm trying to make a constructor for a graph class that accepts a string
I am trying to create a graph out of a data control that I
I have a small python script that creates a graph of data pulled from
I am trying to have two data series plotted in one graph as boxes
I'm trying to remove a specific graph object from the zedgraph, is it possible....?
I am currently trying to implement a graph on a website from a raw
I'm trying to make a graph with highcharts from a csv file. Following is

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.