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.

105 lines
3.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
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>Graph 3D tooltips</title>
  5. <style>
  6. body {font: 10pt arial;}
  7. </style>
  8. <script type="text/javascript" src="../../dist/vis.js"></script>
  9. <script type="text/javascript">
  10. var data = null;
  11. var graph = null;
  12. function custom(x, y) {
  13. return (-Math.sin(x/Math.PI) * Math.cos(y/Math.PI) * 10 + 10);
  14. }
  15. // Called when the Visualization API is loaded.
  16. function drawVisualization() {
  17. var style = document.getElementById("style").value;
  18. var withValue = ['bar-color', 'bar-size', 'dot-size', 'dot-color'].indexOf(style) != -1;
  19. // Create and populate a data table.
  20. var data = new vis.DataSet({});
  21. // create some nice looking data with sin/cos
  22. var steps = 5; // number of datapoints will be steps*steps
  23. var axisMax = 10;
  24. var axisStep = axisMax / steps;
  25. for (var x = 0; x <= axisMax; x+=axisStep) {
  26. for (var y = 0; y <= axisMax; y+=axisStep) {
  27. var z = custom(x,y);
  28. if (withValue) {
  29. var value = (y - x);
  30. data.add({x:x, y:y, z: z, style:value});
  31. }
  32. else {
  33. data.add({x:x, y:y, z: z});
  34. }
  35. }
  36. }
  37. // specify options
  38. var options = {
  39. width: "600px",
  40. height: "600px",
  41. style: style,
  42. showPerspective: true,
  43. showGrid: true,
  44. showShadow: false,
  45. // Option tooltip can be true, false, or a function returning a string with HTML contents
  46. //tooltip: true,
  47. tooltip: function (point) {
  48. // parameter point contains properties x, y, z
  49. return 'value: <b>' + point.z + '</b>';
  50. },
  51. keepAspectRatio: true,
  52. verticalRatio: 0.5
  53. };
  54. var camera = graph ? graph.getCameraPosition() : null;
  55. // Instantiate our graph object.
  56. graph = new vis.Graph3d(document.getElementById('mygraph'));
  57. // Draw our graph with the created data and options
  58. graph.draw(data, options);
  59. if (camera) graph.setCameraPosition(camera); // restore camera position
  60. document.getElementById("style").onchange = drawVisualization;
  61. }
  62. </script>
  63. </head>
  64. <body onload="drawVisualization()">
  65. <p>
  66. <label for="style"> Style:
  67. <select id="style">
  68. <option value="bar">bar</option>
  69. <option value="bar-color">bar-color</option>
  70. <option value="bar-size">bar-size</option>
  71. <option value="dot">dot</option>
  72. <option value="dot-line">dot-line</option>
  73. <option value="dot-color">dot-color</option>
  74. <option value="dot-size">dot-size</option>
  75. <option value="grid">grid</option>
  76. <option value="line">line</option>
  77. <option value="surface">surface</option>
  78. </select>
  79. </label>
  80. </p>
  81. <div id="mygraph"></div>
  82. <div id="info"></div>
  83. </body>
  84. </html>