Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7248651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:10:03+00:00 2026-05-28T22:10:03+00:00

All, I am using the Flot graphing library in my rails application. I currently

  • 0

All,

I am using the Flot graphing library in my rails application. I currently have a page working as expected, however all of the javascript for putting together the flot graph is inline in my “view”.html.erb file.

Is there an easy way to move the static part of the javascript to an external file, generate the dynamic data as regular in the view/controller, and pass it to the javascript file? (through “data-message”??)

The basic layout looks like this:

Controller:

@portfolios = # a bunch of portfolios

View:

<script type="text/javascript">
jQuery(document).ready(function($) {
  // show & hide some stuff
  var options = {
   .......
  };

// THIS IS THE DYNAMIC PORTION

var portfolio_collection = []
var id_lookup = []

<% @portfolios.each do |portfolio| %>
  <% attribute1 = portfolio.attribute1 %>
  <% attribute2 = portfolio.attribute2 %>
  portfolio_collection.push([<%= attribute1 %>,<%= attribute2 %>]);
  id_lookup.push([<%= portfolio.id %>]);
<% end %>

// END DYNAMIC

var plot = $.plot(  // This is the plot command, puts graph in #select div
      $("#select"),
       [ { data: portfolio_collection, label: "Return"} ], 
       options
    );

// A SCHWACK OF JAVASCRIPT
........

</script>

<h1>My HTML content...</h1>

<br />
<div id="select" style="width:600px;height:300px;"></div>
.... a bunch of other divs which renders javascript results from clicking on the graph ....
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:10:03+00:00Added an answer on May 28, 2026 at 10:10 pm

    What I did to get around this issue, is move the flot script to the portfolios.js file. Then I bound a click event to generate the flot graph. In the anchortab I put something like this

    <a id="generate" data-var="<%=@portfolo_data%>" data-var="<%=@portfolo_options%>">Generate Graph</a>
    

    Then in the js file I pulled the call like this

    $(function (){
        $("#generate").click( (event) {
            event.preventDefault();
            eval("var data =" +  $("#generate").data("var") + ";");
            eval("var options =" + $("#generate").data("options") + ";");
            $.plot($("#select"), data, options);
        });
    });
    

    All that is left to do is build out the @portfolio_data and the @portfolio_options strings in the Portfolio Controller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a large number of programmers on different platforms all using CVS. We
i have several controllers which will all be using common functionality. So i have
I've got multiple independent boxes on my page all using {float:left}. There's nothing else
Background We have a WinForms application with Entity Framework 4.2 code-first / FluentAPI using
Any way to submit a form without refreshing the current page at all using
I am having problem with flot library to plot a graph using its line
Working in a team, all using IntelliJ, there's some discussion about checking-in or not
I have 3 different SQL queries from 3 different unrelated tables (all using LIMIT
I am developing an application with multiple windows, all using their own web services.
I have a Win2003 Server running a number of different ASP.NET websites, all using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.