vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.7 KiB

10 years ago
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Data from datasource</title>
  5. <style>
  6. body {font: 10pt arial;}
  7. </style>
  8. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  9. <script type="text/javascript" src="../graph3d.js"></script>
  10. <script type="text/javascript">
  11. var DATASOURCE_URL = "datasource_csv_to_json.php";
  12. var REFRESH_INTERVAL = 1000; // milliseconds
  13. var data = null;
  14. var graph = null;
  15. var query = null;
  16. var draw = function() {
  17. // create an empty table to initialized the graph
  18. data = new google.visualization.DataTable();
  19. data.addColumn('number', 'x');
  20. data.addColumn('number', 'y');
  21. data.addColumn('number', 'z');
  22. data.addColumn('number', 'color');
  23. // specify options
  24. var options = {
  25. width: "600px",
  26. height: "600px",
  27. style: "dot-color",
  28. showPerspective: true,
  29. showGrid: true,
  30. showShadow: false,
  31. keepAspectRatio: true,
  32. verticalRatio: 0.5,
  33. cameraPosition: {
  34. distance: 1.4,
  35. horizontal: 0.0,
  36. vertical: 1.0
  37. }
  38. };
  39. // Instantiate our graph object.
  40. graph = new links.Graph3d(document.getElementById('graph'));
  41. // Draw our graph with the created data and options
  42. graph.draw(data, options);
  43. refresh();
  44. };
  45. google.load("visualization", "1");
  46. // Set callback to run when API is loaded
  47. google.setOnLoadCallback(draw);
  48. // callback function, executed when the response data is received
  49. var redraw = function(response) {
  50. data = response.getDataTable();
  51. graph.redraw(data);
  52. document.getElementById("info").innerHTML = "Updated " + new Date();
  53. };
  54. var refresh = function() {
  55. // send the datasource request
  56. query && query.abort();
  57. query = new google.visualization.Query(DATASOURCE_URL);
  58. query.send(redraw);
  59. window.setTimeout(refresh, REFRESH_INTERVAL);
  60. }
  61. </script>
  62. </head>
  63. <body>
  64. <h1>Refresh data from external datasource</h1>
  65. <p>
  66. This example refreshes once per second the data from an external datasource.
  67. </p>
  68. <p style="font-style:italic;">
  69. Note: this example works only when running it on a PHP server,
  70. as the datasource is a php file.
  71. </p>
  72. <div id="graph"></div>
  73. <div id="info"></div>
  74. </body>
  75. </html>