I need a Bar Graph in Gruff with two Bars.
For two subjects, I loop through to get the values for activity and grade :
sub = ["English", "Maths"]
activity = []
grade = []
sub.each do |sub|
activity.push(sub["activity"].to_i)
grade.push(sub["grade"].to_i)
end
Now, I am using these values for my Bar Graph.
g = Gruff::Bar.new('500x250')
g.maximum_value = 100
g.minimum_value = 0
g.y_axis_increment = 15
g.data( "Activity", activity.inspect)
g.data( "Summative", grade.inspect)
g.labels = {0 => 'English', 1 => 'Language II'}
g.write('images/overall_score.png')
But, this throws an error " comparison of String with 0 failed". I need the data to be printed as
g.data( "Activity", [10,20])
puts activity.inspect prints the array as above ex: [10,20]
Looks like the values are treated as strings. What should I do to resolve this. Any help is greatly appreciated.
Cheers!
Actually inspect
method returns String
. I think you should just pass your arrays to data
method like this:
g.data("Activity", activity)
g.data("Summative", grade)