HTMLcopy
x
1
<!-- rotate controls -->
2
<fieldset>
3
<legend>Rotation control</legend>
4
<button onclick="startRotateZ()">Start</button>
5
<button onclick="clearInterval(autoRotateZ)">Stop</button><br>
6
Z: <input type="range" id="rotationZ" min="-360" max="360" step="1" onInput="rotateZ()">
7
Y: <input type="range" id="rotationY" min="-90" max="90" step="1" onInput="rotateY()">
8
</fieldset>
9
10
<div id="container"></div>
CSScopy
17
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
#container {
8
position: absolute;
9
width: 100%;
10
top: 60px;
11
bottom: 0;
12
}
13
fieldset {
14
font-family: Verdana;
15
font-size: 13px;
16
border: none;
17
}
JavaScriptcopy
45
1
anychart.onDocumentReady(function() {
2
// create chart
3
chart = anychart.surface()
4
// set data
5
chart.data(generateData(hyperbolicParaboloid));
6
7
// display chart
8
chart.container('container').draw();
9
});
10
11
// auto Z rotation
12
function startRotateZ(){
13
autoRotateZ = setInterval(function(){
14
chart.rotationZ(chart.rotationZ()+1);
15
}, 30);
16
};
17
18
// rotation control z
19
var rotateZ = function() {
20
var value = +document.getElementById('rotationZ').value;
21
chart.rotationZ(value);
22
};
23
24
// rotation control y
25
var rotateY = function() {
26
var value = +document.getElementById('rotationY').value;
27
chart.rotationY(value);
28
};
29
30
// generate a data set from function
31
var generateData = function(z_function) {
32
var max_val = 5;
33
var step = 0.5;
34
var output = [];
35
for (var x = -max_val; x <= max_val; x += step) {
36
for (var y = -max_val; y <= max_val; y += step) {
37
output.push([x, y, z_function(x, y)]);
38
}
39
}
40
return output;
41
};
42
// hyperbolic paraboloid function
43
var hyperbolicParaboloid = function(x, y) {
44
return Math.pow(y,2)-Math.pow(x,2);
45
};