Javascript RubyonRails:如何从记录生成一个数组以在Highcharts中显示?
我需要将数据集显示为Highcharts柱形图。我不知道如何将数据传递给Highcharts的Javascript方法来显示我当天的业务流程分数 数据集构建在my BusinessProcess controller中:Javascript RubyonRails:如何从记录生成一个数组以在Highcharts中显示?,javascript,ruby-on-rails,arrays,highcharts,Javascript,Ruby On Rails,Arrays,Highcharts,我需要将数据集显示为Highcharts柱形图。我不知道如何将数据传递给Highcharts的Javascript方法来显示我当天的业务流程分数 数据集构建在my BusinessProcess controller中: @business_process_history = DmMeasure.where("period_id between ? and ? and ODQ_object_id = ?", first_period_id, current_period_id, "BP-#{@b
@business_process_history = DmMeasure.where("period_id between ? and ? and ODQ_object_id = ?", first_period_id, current_period_id, "BP-#{@business_process.id}").select("period_day, score").order("period_id")
这将给出预期的2个字段、10条记录结果,并将完美地显示在HTML表中
更新:
多巴哥的建议给出了预期的阵列阵列
[["20140820", #<BigDecimal:54655c8,'0.997E2',18(45)>], ...]
[“20140820”、#]、…]
但问题并没有解决
以下是函数调用,包括来自Tobago的建议:
<script>
$(function () {
$('#measures').highcharts({
chart: {type: 'column'},
title: {text: 'Data quality trend'},
xAxis: {
title: {text: 'Time'}
},
yAxis: {
title: {text: 'Score'}
},
series: [{
data: <%= @business_process_history.map { |bp| [bp.period_day, bp.score] } %>
}]
});
});
</script>
$(函数(){
$(“#度量”)。高图({
图表:{type:'column'},
标题:{text:'数据质量趋势'},
xAxis:{
标题:{text:'Time'}
},
亚克斯:{
标题:{text:'Score'}
},
系列:[{
数据:
}]
});
});
此脚本在measures DIV中不生成任何内容,而硬编码的值列表会生成一个图形
我试过几种方法,但还是不行
你能帮我吗
非常感谢
致以最良好的祝愿
弗雷德试试:
@business_process_history.map { |bp| [bp.period_day, bp.score] }
多亏了多巴哥的建议,最终的解决方案是:
@business_process_history.map { |bp| [bp.period_day, bp.score.to_f] }
1-带有块的映射方法生成正确的数组数组
2-应用于分数字段的to_f方法确保数据类型满足Highcharts期望
谢谢多巴哥
Fred是的,我以前确实尝试过,使用.inspect方法处理事件,但highcharts仍然没有产生任何结果……好的,我发现BigDecimal数据类型不满足highcharts。我在“分数”字段中添加了.to_f以使其正常工作。谢谢