Wednesday, 15 July 2015

javascript - How can I display the outcome of the for loop in highcharts -



javascript - How can I display the outcome of the for loop in highcharts -

i'm new in (js, rails , highcharts nice) , appreciate help. story have for loop , want display outcome of loop in highcharts. how should this?

<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 %> <% in 0..@calculation.a %> <% @newamount = ((@amount/(@percent)) + @amount) %> <%= "#{i}" + " - #{@amount}" %><br /> <% @amount=@newamount %> <% end %> <script type="text/javascript" charset="utf-8"> $(function() { new highcharts.chart({ chart: { renderto: "calculations_chart" }, title: { text: "sum year" }, xaxis: { text: "years" }, yaxis: { title: { text: "sum" } }, series: [{ data: //for loop? }] }); }); </script> <div id="calculations_chart" style="width:560px; height:300px;"></div>

if have single value computed in loop can place right in location want it

series: [{ data: [<%=@amount%>] }]

or if have series of info stored somewhere want iterate on , add together them chart

series: [ { data: [ <% in 0..@calculation.a %> <% @amount = ((@amount/(@percent)) + @amount) %> <%= @amount %>, <% end %> ]} ]

this lot of logic in page, might want think moving controller or model. super re usability in multiple places can have action serves info in json asynchronously in pages need it.

edited match highchart format

javascript ruby-on-rails highcharts

No comments:

Post a Comment