0

I'm using Play Framework and I want to reproduce the plots that I have in an HTML file with the data I pass from the controller to this HTML file, but this reproduction has to be in the index page. That's to say, I pass the data from a simulation to the HTML page and there I plot the charts, and I'd like to get this data plotted properly in this HTML file let's call it "File 2" to the index HTML, let's call it "page 1".

I would like to be able to obtain this data plotted (the "arrays", let's say) from file 2 to the file 1 so I would just need to type: $.plot(...) and avoid creating the arrays of data again (perhaps I can link the file2 with something like @file2.html.data1, #{extends 'file2.html' /} or something similar). How can I get the data from the HTML where I plot it and pass it from an this HTML file to the index HTML page? Thanks!

(If if helps, I have all the plots stored in variables (myPlot = $.plot($("#placeholder"), data, options);, myPlot2 = $.plot($("#placeholder2"), data, options);, ... in the file where I initially plot them).

jquery_stack
  • 261
  • 4
  • 17
  • Your description is not fully clear to me. Perhaps you could provide some source listings? As for now, it seems to me that the only missing piece you need is either using a template inside javascript file / script tag, or use AJAX. – Krystian Laskowski Jul 06 '15 at 11:35
  • I'll try to explain myself better: I have the parameters from a simulation in an html file in which I plot them using Flot Charts (Javascript). However, I need these variables in the index html file as well, like an "extraction" of them when I click a button or something, in order to reproduce the plots in this page too. Thanks! – jquery_stack Jul 07 '15 at 06:48

1 Answers1

0

I believe that augmenting following solution may solve your problem: https://stackoverflow.com/a/20874089/4506430

The only possible difference in your case is that file2.html might be dynamic (you haven't stated that, but that's my guess judging from the context). If it is, you need to render it server-side.

EDIT After reconsideration, I realized that storing data inside session scope would be better solution for you. Thanks to session scope you can share the data between multiple controllers, and embed it in multiple html files.

Community
  • 1
  • 1
  • Will this make all the variables in file 2 available in file 1 or will it just work as a "copy-paste" of existing content? (in this case, the charts) – jquery_stack Jul 07 '15 at 08:21
  • This will copy-paste existing content. To just reuse variables, you would have to re-engineer your current solution, so that the server hold the plot data and html code separately. – Krystian Laskowski Jul 07 '15 at 08:33
  • Whoa, that's a bit abstract. Do you have any basic example so I can understand better? Thanks very much for your help! – jquery_stack Jul 07 '15 at 08:44
  • There is no way to access a Javascript variable stored in one html file from another. However, there are numerous ways to store them in shared space, e.g. web storage, server session scope, or just create a controller that serves the data dynamically using ajax. – Krystian Laskowski Jul 07 '15 at 11:51
  • I'd be interested in knowing how to do the last option mentioned, if that's not too much trouble. Do you have a simple example or guidance on how to do it? Thanks! – jquery_stack Jul 08 '15 at 08:16