HTMLcopy
x
1
<!-- update data on button click -->
2
<fieldset>
3
<legend>Choose Function to Display</legend>
4
<button onclick="chart.data(generateData(plane));">Plane</button>
5
<button onclick="chart.data(generateData(parabaloid));">Paraboloid</button>
6
<button onclick="chart.data(generateData(hyperbolicParaboloid));">Hyperbolic Paraboloid</button>
7
Precision: <input type="number" id="step" step="0.1" value="1" min="0.5" max="1" size="3">
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: 55px;
11
bottom: 0;
12
}
13
fieldset {
14
font-family: Verdana;
15
font-size: 13px;
16
border: none;
17
}
JavaScriptcopy
32
1
anychart.onDocumentReady(function() {
2
// create chart
3
chart = anychart.surface()
4
// set data
5
chart.data(generateData(parabaloid));
6
// display chart
7
chart.container('container').draw();
8
});
9
// generate a data set from function
10
var generateData = function(z_function) {
11
var max_val = 5;
12
var step = +document.getElementById('step').value;
13
var output = [];
14
for (var x = -max_val; x <= max_val; x += step) {
15
for (var y = -max_val; y <= max_val; y += step) {
16
output.push([x, y, z_function(x, y)]);
17
}
18
}
19
return output;
20
};
21
// parabaloid function
22
var parabaloid = function(x, y) {
23
return Math.pow(x, 2)+Math.pow(y,2);
24
};
25
// hyperbolic paraboloid function
26
var hyperbolicParaboloid = function(x, y) {
27
return Math.pow(y,2)-Math.pow(x,2);
28
};
29
// plane function
30
var plane = function(x, y) {
31
return x + y;
32
};