# SVG::Graph::Plot

**URL:** <https://www.ruby-forum.com/t/svg-plot/89762>\
**Category:** Ruby\
**Created:** [March 22, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/svg-plot/89762 "2007-03-22T16:06:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rwl4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rwl4](https://www.ruby-forum.com/u/rwl4)\
**Post date:** [March 22, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/svg-plot/89762/1 "2007-03-22T16:06:28Z")

</div>

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,
