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.

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