HTMLcopy
1
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
x
1
// peaks function
2
function peaks(val) {
3
var func =
4
'3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) - 1/3*exp(-(x+1).^2 - y.^2)';
5
var result = [];
6
for (var x = -val; x <= val + val / 15; x += val / 15) {
7
for (var y = -val; y <= val + val / 15; y += val / 15) {
8
result.push([x, y, math.eval(func, { x: x, y: y })]); // eslint-disable-line no-undef
9
}
10
}
11
return result;
12
}
13
14
anychart.onDocumentReady(function () {
15
// create surface chart
16
var chart = anychart.surface(peaks(3));
17
18
// enable and configure color range
19
var colorRange = chart.colorRange().enabled(true).orientation('right');
20
21
// set color range labels settings
22
colorRange
23
.labels()
24
.fontColor('#333')
25
.format(function () {
26
return this.value.toFixed(2);
27
});
28
29
// set default chart y & z rotation
30
chart.rotationY(15);
31
chart.rotationZ(20);
32
33
// set chart's mesh settings
34
chart.stroke('1 #fff .2');
35
36
// disable chart's box
37
chart.box('#aaa .2');
38
39
// set chart's padding
40
chart.padding(0, 50, 25);
41
42
// set X/Y/Z axis stroke color
43
chart.xAxis().stroke('#000');
44
chart.yAxis().stroke('#000');
45
chart.zAxis().stroke('#000');
46
47
// set X/Y/Z axis ticks stroke color
48
chart.xAxis().ticks().stroke('#aaa .2');
49
chart.yAxis().ticks().stroke('#aaa .2');
50
chart.zAxis().ticks().stroke('#aaa .2');
51
52
// set minimum and maximum for the X/Y/Z scales
53
chart.xScale().minimum(-3).maximum(3);
54
chart.yScale().minimum(-3).maximum(3);
55
chart.zScale().minimum(-8).maximum(8);
56
57
// set X axis labels settings
58
chart
59
.xAxis()
60
.labels()
61
.fontColor('#333')
62
.format(function () {
63
return this.value.toFixed(2);
64
});
65
66
// set Y axis labels settings
67
chart
68
.yAxis()
69
.labels()
70
.fontColor('#333')
71
.format(function () {
72
return this.value.toFixed(2);
73
});
74
75
// set Z axis labels settings
76
chart
77
.zAxis()
78
.labels()
79
.fontColor('#333')
80
.format(function () {
81
return this.value.toFixed(2);
82
});
83
84
// hide the last label in Y axis
85
chart.yAxis().drawLastLabel(false);
86
87
// set grids settings
88
chart.xGrid().stroke('#aaa .2');
89
chart.yGrid().stroke('#aaa .2');
90
chart.zGrid().stroke('#aaa .2');
91
92
// set container id for the chart
93
chart.container('container');
94
95
// initiate chart drawing
96
chart.draw();
97
});