如何声明字符串和 int 类型的二维数组?
我想做这样的事情
@products.each do |p|
array = [p.title, p.price]
end
但我收到一条错误消息,说无法将字符串转换为 int
问题是我只能调用 f.series() 一次,我需要一个数组来保存我的所有数据
f.series(:name => 'Product Sales', :data => array)
我正在尝试按照此代码创建饼图
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