How do i declare a 2D array of type string and int?
I want to do something like this
@products.each do |p|
array = [p.title, p.price]
end
But i get an error saying cannot convert string to int
The problem is i can only call f.series() once and i need an array to hold all of my data
f.series(:name => 'Product Sales', :data => array)
I’m trying to follow this code to create a pie chart
def pie_chart
@categories = generate_categories(6)
@numbers = generate_numbers(6)
assoc = []
@categories.each_with_index {|c,i| assoc << [c, @numbers[i]]}
@highchart = HighChart.new('graph') do |f|
f.title(:text => 'Flowers in Yard')
f.options[:chart][:defaultSeriesType] = "pie"
f.options[:x_axis][:categories] = @categories
f.series(:type => 'pie', :name => 'Flower Presence', :data => assoc)
end
def generate_numbers(number)
numbers = [rand(number)]
(1...number).each_with_index {|v, i| numbers << (rand(number)+1)}
numbers
end
def generate_categories(number)
cats = ['Sunflower', 'Magnolia', "Rose", 'Lily', 'Tulip', 'Iris']
cats[0...number]
end
In ruby you can save different type of the element in the single array like following
So if you want to save array of array like following
Use following
OR just
Edited to show the access the 2D Array