我是新來的(JS,Rails和highcharts,但他們真的很好),我真的很感謝一些幫助。我的故事是我有一個for loop
,我想在highcharts
中顯示for循環的結果。我應該怎麼做?我如何在highcharts中顯示for循環的結果
<p>A n: <%= @calculation.a_n %></p>
<p>H: <%= @calculation.h %></p>
<p>K: <%= @calculation.k %></p>
<p>P: <%= @calculation.p %></p>
<p>A: <%= @calculation.a %></p>
<small>T: <%= @calculation.created_at %></small>
<br /><br />
<%= @calculation.a_n %> <br />
<% @amount = (@calculation.h * @calculation.k) %>
<% @percent = (@calculation.h * @calculation.k)/@calculation.p %>
<% for i in [email protected] do %>
<% @newAmount = ((@amount/(@percent)) + @amount) %>
<%= "#{i}" + " - #{@amount}" %><br />
<% @[email protected] %>
<% end %>
<script type="text/javascript" charset="utf-8">
$(function() {
new Highcharts.Chart({
chart: {
renderTo: "calculations_chart"
},
title: {
text: "Sum for a year"
},
xAxis: {
text: "Years"
},
yAxis: {
title: {
text: "Sum"
}
},
series: [{
data: //for loop?
}]
});
});
</script>
<div id="calculations_chart" style="width:560px; height:300px;"></div>
什麼是循環你的意思是?預先計算的數據服務器端?將json編碼的輸出放在頁面上的某處(scipt標籤內),解碼並將其放到數據中 –