Ruby on rails RubyonRails的html绘制矩形,内部包含文本
这是我的目标,我有一堆数据,一个包含名称值的名称数组,以及相同的重量、高度和颜色 在我的控制器函数中,我有以下几点 我的数据库名Ruby on rails RubyonRails的html绘制矩形,内部包含文本,ruby-on-rails,html,svg,html5-canvas,Ruby On Rails,Html,Svg,Html5 Canvas,这是我的目标,我有一堆数据,一个包含名称值的名称数组,以及相同的重量、高度和颜色 在我的控制器函数中,我有以下几点 我的数据库名 def display people= Person.all end 和内部display.html.erb: <h1> Display Result</h1> <div id='chart'> <% @people.each do |x| %> <svg width="<%=x
def display
people= Person.all
end
和内部display.html.erb:
<h1> Display Result</h1>
<div id='chart'>
<% @people.each do |x| %>
<svg width="<%=x.weight%>" height="<%=x.height%>">
<rect width = "<%=x.weight%>" height="<%=x.height%>" style="fill:<%=x.color%>;stroke-width:3;stroke:black">
<text fill="#ffffff",50,50><%= x.name %></text>
</svg>
<% end %>
</div>
显示结果
想要上面这样的东西,因为长方形随高度和重量而变化,重量是水平的,高度是垂直的
已经能够绘制矩形,但需要将文本放在矩形内,你知道如何将其定位在矩形内吗?
你知道我该怎么修吗,提前谢谢你的帮助!!
使用轨道连接来固定高度和宽度
<h1> Display Result</h1>
<div id='chart'>
<%= @people.each do |x| %>
<svg width = "500" height = "500">
<rect width="<%= x.weight %>" height="<%= x.height%>" style="fill:<%= x.color %>;stroke-width:3;stroke:black">
<text fill="#ffffff">x.name</text>
</svg>
<% end %>
</div>
<%= link_to 'Back', {:controller => 'people', :action => 'index'}, id:'proceedss' %>
显示结果
x、 名字
'people',:action=>'index'},id:'proceedss'>
使用轨道连接来固定高度和宽度
<h1> Display Result</h1>
<div id='chart'>
<%= @people.each do |x| %>
<svg width = "500" height = "500">
<rect width="<%= x.weight %>" height="<%= x.height%>" style="fill:<%= x.color %>;stroke-width:3;stroke:black">
<text fill="#ffffff">x.name</text>
</svg>
<% end %>
</div>
<%= link_to 'Back', {:controller => 'people', :action => 'index'}, id:'proceedss' %>
显示结果
x、 名字
'people',:action=>'index'},id:'proceedss'>