2017-02-09 46 views
2

我創建了一個新的應用程序,並在gemfile地圖中添加了gem'heatmap'。然後,我做了一個bundle install,但我不知道如何編寫關於哪個文件的熱圖代碼。如何使用ruby-on-rails生成熱圖?

這是我的嘗試:

map = Heatmap.new 
map << Heatmap::Area.new(1, 10) 
map << Heatmap::Area.new(5, 20) 
map << Heatmap::Area.new(17, 10) 
map << Heatmap::Area.new(25, 38) 
map << Heatmap::Area.new(35, 70) 
map << Heatmap::Area.new(15, 90) 
map << Heatmap::Area.new(27, 60) 
map.output('simple.png') 
+0

請一步一步解釋。 – test

回答

0

如果我沒看錯你試圖使用熱圖寶石(https://github.com/hyfen/heatmap,最後提交於2013年11月9日)

嘗試初始化熱圖對象這樣Heatmap::Map.new的自述說,然後添加點heatmap.points << Heatmap::Point.new(0, 0, 0.1)

用法是這樣的:

require 'heatmap' 

heatmap = Heatmap::Map.new 

heatmap.points << Heatmap::Point.new(0, 0, 0.1) 
heatmap.points << Heatmap::Point.new(80, 5, 0.3) 
heatmap.points << Heatmap::Point.new(10, 5, 0.2) 
heatmap.points << Heatmap::Point.new(23, 5, 0.8) 
heatmap.points << Heatmap::Point.new(50, 50, 0.9) 
heatmap.points << Heatmap::Point.new(20, 10, 0.9) 
heatmap.points << Heatmap::Point.new(100, 85, 1.0) 
heatmap.points << Heatmap::Point.new(100, 60, 1.0) 
heatmap.points << Heatmap::Point.new(90, 90, 1.0) 
heatmap.points << Heatmap::Point.new(90, 30, 0.8) 
heatmap.points << Heatmap::Point.new(90, 45, 0.9) 

heatmap.output("output.png") 
+0

我在軌道上的ruby中創建了新的應用程序。添加了gem熱圖,但沒有找到使用此代碼創建熱圖的下一步驟。 – test

+0

在視圖中查看它是否真正起作用,然後如果數據是動態的,則可以由控制器將其作爲實例變量發送。 –

+0

如果用戶點擊頁面然後創建熱圖,是否可能? – test