SVG::Graph::Plot

R

Raymond Law

I encountered a problem when using SVG::Graph. I have the following
code that generate a simple plot:

require 'SVG/Graph/Plot'

# This does not work.
data= [0.107,9, 0.128,1, 0.163,2, 0.188,4, 0.192,6, 0.5,5.5]

# This works fine.
#data= [0.107,9, 0.128,1, 0.163,2, 0.188,4, 0.192,6, 1.5,5.5]

graph = SVG::Graph::plot.new({
:height => 500,
:width => 800,
:key => true,
:scale_x_integers => true,
:scale_y_integerrs => true,
})

graph.add_data({
:data => data,
:title => 'Projected'
})

f = File.new("plot.svg", "w+")
f.write(graph.burn())
f.close

The error is:

123 rlaw ~/svg_graph/test > ruby plot.rb
/usr/local/lib/ruby/site_ruby/1.8/SVG/Graph/Plot.rb:206:in `-': nil
can't be coerced into Float (TypeError)
from /usr/local/lib/ruby/site_ruby/1.8/SVG/Graph/Plot.rb:206:in
`field_width'
from /usr/local/lib/ruby/site_ruby/1.8/SVG/Graph/Graph.rb:522:in
`draw_x_labels'
from /usr/local/lib/ruby/site_ruby/1.8/SVG/Graph/Graph.rb:488:in
`draw_graph'
from /usr/local/lib/ruby/site_ruby/1.8/SVG/Graph/Graph.rb:203:in
`burn'
from plot.rb:19
124 rlaw ~/svg_graph/test >

Basically, when x's are very small (i.e. smaller than 1?), I get the
above error. Is this a known bug, or am I just not using it right?

Thank you.

Ray,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top