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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:56:50+00:00 2026-05-26T08:56:50+00:00

I have this problem. i think it is simple but i just couldn’t get

  • 0

I have this problem. i think it is simple but i just couldn’t get it right.
Im building graph and table using gruff.I have a x axis scaled from month 01 to 12
The data shud hv bn plotted in month 09 and 10 but it is plotted to month 08 and 10.

def stat1
  @yeara = params[:year]
  @games = Games.find(:all)
  g = Gruff::StackedBar.new('800x450')
  g.theme = {
    :colors => ['#138F6A','#330000','#ff6600', '#3bb000', '#1e90ff', '#efba00', '#0aaafd'],
    :marker_color => '#aaa',
    :background_colors => ['#eaeaea', '#fff']
  }
  g.hide_title = true

  @dr = Game.count(:all, :conditions=> ["game_id= ? and DATE_FORMAT(date, '%Y')= ?",1,@yeara], :group => "DATE_FORMAT(date, '%m')", :order =>"date ASC")
  @df = Game.count(:all, :conditions=> ["game_id= ? and DATE_FORMAT(date, '%Y') = ?",2,@yeara], :group => "DATE_FORMAT(date, '%m')", :order =>"date ASC")
# all 12 month a year      
   @full = Hash["01",0,"02",0,"03",0,"04",0,"05",0,"06",0,"07",0,"08",0,"09",0,"10",0,"11",0,"12",0]      
  year = (@dr.keys |@df.keys|@full.keys).sort
  @keys = Hash[*year.collect {|v| [year.index(v),v.to_s] }.flatten]

# Plot data to table
  @dfdr = Array.new
  @dfdr <<  @keys.collect {|k,v| @df[v].nil? ? 0 : @df[v]}
  @dfdr <<  @keys.collect {|k,v| @dr[v].nil? ? 0 : @dr[v]}

# Plot data to graph
  g.data("Adam", @keys.collect {|k,v| @dr[v].nil? ? 0 : @dr[v]}) 
  g.data("Eve", @keys.collect {|k,v| @df[v].nil? ? 0 : @df[v]})
  g.labels = @keys

  g.write("#{RAILS_ROOT}/public/images/game.png")  
  render(:layout => false)

here are some explanation
the output for

@dr = Game.count(:all, :conditions=> ["game_id= ? and DATE_FORMAT(date, '%Y')= ?",1,@yeara], :group => "DATE_FORMAT(date, '%m')", :order =>"date ASC")

=> [[“09”,3],[“10”,1]

@df = Game.count(:all, :conditions=> ["game_id= ? and DATE_FORMAT(date, '%Y') = ?",2,@yeara], :group => "DATE_FORMAT(date, '%m')", :order =>"date ASC")

=> [[“10”,2]]

trying to trace where went wrong..but ran out of idea.
please point something out to me.wish i could paste the graph but im not eligible yet say stackoverflow. 😉

thank u

  • 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-26T08:56:51+00:00Added an answer on May 26, 2026 at 8:56 am

    OK got it.

    @keys.collect {|k,v| @df[v].nil? ? 0 : @df[v]
    

    the @keys are in unsorted order.So simply sort it first.

    @keys.sort.collect {|k,v| @df[v].nil? ? 0 : @df[v]
    

    Thank you all. :))))) Sorry if anything. 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have what I think is a simple problem but have been unable to
I have spent too much time on this problem and am beginning to think
I have this problem I'm hoping someone knows the answer to. I have an
I have this problem where I open Visual Studio and the internal windows are
i have this problem to find a particular xml node l have post this
I have this problem I've been trying to tackle for a while. I have
i have this problem: ms-access could not delete and i found a potential solution
I have this problem in my ASP.NET application where I'm seeing some of my
I have this problem that my sites uses alot of ajax and when a
I have this problem containing some inequations and requirement to minimize a value. After

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.