Forum: Ruby Gruff and labeling

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7007f89eaa00d75c6733723de5aaff23?d=identicon&s=25 Trick Nick (silentd3at4)
on 2008-11-25 22:38
I have everything done my output goes to a graph everything is fine
except now i need to put labels on the x axis for each decade.  So
currently Y-axis Says: population X-axis says: years and they Y-Axis has
the years posted on the side for each row.  BUT how do i get 1951 - 2004
to post on the bottom the graph (every decade not ever year)

Heres wat i got so far plz any help appreciated?

ARGV.each do |arg|
countriesString << ",\"#{arg.to_s}\""
form_params['my_countries'] = "#{countriesString}"
#FORM PARAMS COMPLETED

#COLLECT DATA
    results =
Net::HTTP.post_form(URI.parse('http://pwt.econ.upenn.edu/php_site/...pwt62/pwt62_...),
form_params)
    parse_page = Hpricot(results.body)
    popData_H = (parse_page/"pre").inner_html
    popCSV = CSV.parse(popData_H.to_s {|f| f.read})
#END COLLECT DATA
#PREPARE TO GRAPH
    label = arg
    popdata = popCSV.map { |x| x[3].to_i }
    if popdata[2]% 10 == 0 || popdata[2] == 1951 || popdata[2] == 2004
        labels = popdata
    end
    popdata.delete(0)
    pg.data(label, popdata)
    pg.x_axis_label = "Years"
    pg.y_axis_label = "Population"
    countriesString = ''
end

pg.write('population_graph.png')
7007f89eaa00d75c6733723de5aaff23?d=identicon&s=25 Trick Nick (silentd3at4)
on 2008-11-25 23:03
::Realized I didnt have year info gathered from my CSV so i added that
but still need help on how to put the dates(Decades) as the x-col values
=P

require 'net/http'
require 'rubygems'
require 'gruff'
require 'csv'
require 'hpricot'

pg = Gruff::Line.new
form_params = Hash.new
countriesString = ''

#GET FORM PARAMS
form_params = {
    'my_vars' => ',+POP',
    'my_yrs' =>
'1950,1951,1952,1953,1954,1955,1956,1957,1958,1959,1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004',
    'selected_vars'   => 'POP',
    'format_selected' => 'csv'
}

ARGV.each do |arg|
countriesString << ",\"#{arg.to_s}\""
form_params['my_countries'] = "#{countriesString}"
#FORM PARAMS COMPLETED

#COLLECT DATA
    results =
Net::HTTP.post_form(URI.parse('http://pwt.econ.upenn.edu/php_site/pwt62/pwt62_ret...),
form_params)
    parse_page = Hpricot(results.body)
    popData_H = (parse_page/"pre").inner_html
    popCSV = CSV.parse(popData_H.to_s {|f| f.read})
#END COLLECT DATA
#PREPARE TO GRAPH
    label = arg
    popdata = popCSV.map { |x| x[3].to_i }
    yeardata = popCSV.map { |x| x[2].to_i }
    popdata.delete(0)
    yeardata.delete(0)
        yeardata.each do |x|
            if x % 10 == 0 || x == 1951 || x == 2004
            labels = yeardata[2]
            end
        end
    pg.data(label, popdata)
    pg.x_axis_label = "Years"
    pg.y_axis_label = "Population"
    countriesString = ''
end
puts pg.methods.sort
pg.write('population_graph.png')
This topic is locked and can not be replied to.