【问题标题】:html of Ruby on rails draw rectangle with text insideRuby on rails 的 html 绘制带有文本的矩形
【发布时间】:2016-05-07 23:32:33
【问题描述】:

这是我的目标,我有一堆数据,一个包含名称值的名称数组,以及相同的重量、高度、颜色。

所以在我的控制器功能中,我有以下内容 我的数据库名称人

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>

想要像上面一样,因为矩形随高度和重量而变化,重量是水平的,高度是垂直的。

已经可以绘制矩形,但需要将文本放在矩形内,知道如何将它定位在矩形内吗? 知道如何解决它,在此先感谢您的帮助!!

【问题讨论】:

    标签: ruby-on-rails html svg html5-canvas


    【解决方案1】:

    使用 rails 连接来固定高度和宽度。

    <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' %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-30
      • 2015-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多