gpt4 book ai didi

javascript - 语法错误: illegal character when posting array to data attribute of highcharts

转载 作者:行者123 更新时间:2023-11-28 08:13:12 25 4
gpt4 key购买 nike

我有一个 Rails 应用程序,它使用 highcharts 来显示 2 种货币的折线图。但是,当我在浏览器上运行该应用程序时,我在 firebug 中不断收到以下错误

SyntaxError: illegal character
data: #<Forex::ActiveRecord_Relation:0xc743144>

我无法弄清楚我的 javascript 代码有什么问题,因为它不包含 highcharts 的以下数据属性

#&lt 

这是我的代码:

<div id="forex">
<script type="text/javascript" charset="utf-8">
$(function() {
new Highcharts.Chart({
chart: {
renderTo: "forex"
},
title: {
text: "Forex"
},
xAxis: {
type: "datetime"
},
yAxis: {
title: {
text: "Shillings"
}
},
tooltip: {
formatter: function() {
return Highcharts.dateFormat("%B %e, %Y", this.x) + ': ' +
"$" + Highcharts.numberFormat(this.y, 2);
}
},
series: [
<% { "Dollar" => Forex.dollar, "British Pound" => Forex.british_pound }.each do |name, value| %>
{
name: "<%= name %>",
pointInterval: <%= 1.day * 1000 %>,
pointStart: <%= 3.weeks.ago.to_i * 1000 %>,
data: <%= value %>
},
<% end %>
]
});
});
</script>
</div>

我正在从 forex.rb 上定义的范围填充数据,如下所示

scope :dollar, -> { where(:us_dollar != 0) }
scope :british_pound, -> { where(:british_pound != 0 ) }

我按照Santosh的回答做了:

<% { "Dollar" => Forex.dollar, "British Pound" => Forex.british_pound }.each do |name, value| %>
<p><%= name == 'Dollar' ? a=value.pluck(:us_dollar) : b=value.pluck(:british_pound) %></p>
<% end %>

但是这会打印出 2 个空数组,而我的表属性中有 2 个值

美元:88.27 英镑:149.23

最佳答案

您的作用域语法错误

将条件更改为

where(["us_dollar != ?", 0])

将数据更改为

data: <%= name == 'Dollar' ? value.pluck(:us_dollar) : value.pluck(:british_pound) %>

关于javascript - 语法错误: illegal character when posting array to data attribute of highcharts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23905702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com