UNPKG

3.12 kBHTMLView Raw
1<!doctype html>
2<html>
3<head>
4 <title>Graph 3D Axis Ticks</title>
5
6 <style>
7 body {font: 10pt arial;}
8 </style>
9
10 <script type="text/javascript" src="../../dist/vis-graph3d.min.js"></script>
11
12 <script type="text/javascript">
13 var data = null;
14 var graph = null;
15
16 function custom(x, y) {
17 return (-Math.sin(x/Math.PI) * Math.cos(y/Math.PI) * 10 + 10) * 1000;
18 }
19
20 // Called when the Visualization API is loaded.
21 function drawVisualization() {
22 var style = document.getElementById('style').value;
23 var withValue = ['bar-color', 'bar-size', 'dot-size', 'dot-color'].indexOf(style) != -1;
24
25 // Create and populate a data table.
26 data = new vis.DataSet();
27
28 // create some nice looking data with sin/cos
29 var steps = 5; // number of datapoints will be steps*steps
30 var axisMax = 10;
31 var axisStep = axisMax / steps;
32 for (var x = 0; x <= axisMax; x+=axisStep) {
33 for (var y = 0; y <= axisMax; y+=axisStep) {
34 var z = custom(x,y);
35 if (withValue) {
36 var value = (y - x);
37 data.add({x:x, y:y, z: z, style:value});
38 }
39 else {
40 data.add({x:x, y:y, z: z});
41 }
42 }
43 }
44
45 // specify options
46 var options = {
47 width: '600px',
48 height: '600px',
49 style: style,
50 showPerspective: true,
51 showGrid: true,
52 showShadow: false,
53
54 // Option tooltip can be true, false, or a function returning a string with HTML contents
55 //tooltip: true,
56 tooltip: function (point) {
57 // parameter point contains properties x, y, z
58 return 'value: <b>' + point.z + '</b>';
59 },
60
61 xValueLabel: function(value) {
62 return vis.moment().add(value, 'days').format('DD MMM');
63 },
64
65 yValueLabel: function(value) {
66 return value * 10 + '%';
67 },
68
69 zValueLabel: function(value) {
70 return value / 1000 + 'K';
71 },
72
73 keepAspectRatio: true,
74 verticalRatio: 0.5
75 };
76
77 var camera = graph ? graph.getCameraPosition() : null;
78
79 // create our graph
80 var container = document.getElementById('mygraph');
81 graph = new vis.Graph3d(container, data, options);
82
83 if (camera) graph.setCameraPosition(camera); // restore camera position
84
85 document.getElementById('style').onchange = drawVisualization;
86 }
87 </script>
88
89</head>
90
91<body onload="drawVisualization()">
92
93<p>
94 <label for="style"> Style:
95 <select id="style">
96 <option value="bar">bar</option>
97 <option value="bar-color">bar-color</option>
98 <option value="bar-size">bar-size</option>
99
100 <option value="dot">dot</option>
101 <option value="dot-line">dot-line</option>
102 <option value="dot-color">dot-color</option>
103 <option value="dot-size">dot-size</option>
104
105 <option value="grid">grid</option>
106 <option value="line">line</option>
107 <option value="surface">surface</option>
108 </select>
109 </label>
110</p>
111
112<div id="mygraph"></div>
113
114<div id="info"></div>
115</body>
116</html>