plot.html 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <title>SPM Plot</title>
  6. <script src="js/plotly.min.js"></script>
  7. </head>
  8. <body>
  9. <div id="plotly" style="height: 650px;width: 800px;"></div>
  10. <script type="text/javascript">
  11. var queries = location.search.split("?")[1];
  12. if (typeof(queries) === "undefined") {
  13. alert("No data!");
  14. }
  15. var query = queries.split("&");
  16. for (var i = 0; i < query.length; i++) {
  17. var datatype = query[i].split("=")[0];
  18. var filename = query[i].split("=")[1];
  19. var ext = filename.split('.').pop();
  20. if (ext === "js") {
  21. var firstScript = document.getElementsByTagName('script')[0];
  22. var js = document.createElement('script');
  23. js.src = filename;
  24. var data = {}, layout = {title: ""}, options = {};
  25. js.onload = function () {
  26. Plotly.plot("plotly", data, layout, options);
  27. }
  28. firstScript.parentNode.insertBefore(js, firstScript);
  29. } else {
  30. Plotly.d3.json(filename, function(err, fig) {
  31. if (err) alert("Could not read data!");
  32. if (fig.layout === "undefined") {
  33. fig.layout = {title: ""};
  34. }
  35. if (fig.options === "undefined") {
  36. fig.options = {};
  37. }
  38. Plotly.plot("plotly", fig.data, fig.layout, fig.options);
  39. });
  40. }
  41. }
  42. </script>
  43. </body>
  44. </html>