当我的鼠标指针悬停在图表上时,是否可以使用标签和单位?目前只有这个数字.
对于下面的示例,我想表明:

我的选项如下:
var options = {
//Boolean - Show a backdrop to the scale label
scaleShowLabelBackdrop : true,
//Boolean - Whether to show labels on the scale
scaleShowLabels : true,
// Boolean - Whether the scale should begin at zero
scaleBeginAtZero : true,
scaleLabel : "<%%= Number(value) + ' %'%>",
legendTemplate: "<ul class=\"<%%=name.toLowerCase()%>-legend\"><%% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%%=datasets[i].strokeColor%>\"></span><%%if(datasets[i].label){%><%%=datasets[i].label%> <strong><%%=datasets[i].value%></strong><%%}%></li><%%}%></ul>",
tooltipTemplate: "<%%= value %> Label"
}
Run Code Online (Sandbox Code Playgroud)
使用scaleLabel选项,我在Y轴上显示%,但在悬停弹出窗口中没有显示...
如果我们有这样create_widget定义的方法:
def create_widget(size, properties)
puts properties.class #=> Hash
puts properties[:id] #=> table22
end
Run Code Online (Sandbox Code Playgroud)
有什么区别:
create_widget(6, {:id => "table22", :class => "Cart"})
create_widget(6, :id => "table22", :class => "Cart")
create_widget(6, id: "table22", class: "Cart")
Run Code Online (Sandbox Code Playgroud)
在任何情况下,第二个参数都是a Hash,并呈现相同的结果.
我有一个网址:
xxxx/xxx?status=2
Run Code Online (Sandbox Code Playgroud)
我:status从URL 获得了参数的值,将其转换为整数,并尝试对其使用between方法:
params[:status].to_i.between.(0, 3)
Run Code Online (Sandbox Code Playgroud)
但我得到如下错误:
undefined method `between' for 1:Fixnum
Run Code Online (Sandbox Code Playgroud)
我检查了班级祖先:
params[:status].to_i.class.ancestors
# => [Fixnum, JSON::Ext::Generator::GeneratorMethods::Fixnum, Integer, Numeric, Comparable, Object, ActiveSupport::Dependencies::Loadable, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject]
Run Code Online (Sandbox Code Playgroud)
我可以看到Comparable,所以我不明白为什么我不能这样做。
这是我想要排序的模型.
我有一个User人可以有多个Post,每个人都有很多Statistic.
总结一下这就是我所拥有的:
class User < ActiveRecord::Base
has_many :posts
has_many :statistics
end
class Post < ActiveRecord::Base
belongs_to :user
has_many :statistics
end
class Statistic < ActiveRecord::Base
belongs_to :post
belongs_to :user
end
Run Code Online (Sandbox Code Playgroud)
我最终想要的是两张桌子(一个牢房=一天):
对于第一个,我使用以下方法完成了:
# Group by day all statistics from one user
stats_by_date = current_user.statistics.group_by { |s| s.created_at.to_date }
# Transform the hash into an Array (one cell = one day)
@overall_statistics = stats_by_date.values
Run Code Online (Sandbox Code Playgroud)
对于第二个,我成功地将我的结果分组为Post ID和days但我不知道如何将其转换为可利用的Array,它表示每个Post ID的一个表,并且在每个表中为一天的一个单元格:
# Group statistics by posts
stats_by_post …Run Code Online (Sandbox Code Playgroud) hash ×2
ruby ×2
arrays ×1
associations ×1
chart.js ×1
group-by ×1
javascript ×1
jquery ×1
label ×1