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