HTMLcopy
x
1
<!-- rotate controls -->
2
<fieldset>
3
<legend>Rotation controls:</legend>
4
Y: <input type="range" id="rotationY" min="-90" max="90" step="1" value="40" onInput="rotateY()">
5
Z: <input type="range" id="rotationZ" min="-180" max="180" step="1" value="60" onInput="rotateZ()">
6
</fieldset>
7
8
<div id="container"></div>
CSScopy
15
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
9
10
fieldset {
11
font-family: Verdana;
12
font-size: 13px;
13
border: none;
14
margin-top: 20px;
15
}
JavaScriptcopy
96
1
let theChart;
2
anychart.onDocumentReady(function () {
3
anychart.data.loadJsonFile(
4
'https://gist.githubusercontent.com/awanshrestha/9d0f4c864817d5ee043126f63f1f4d02/raw/91cb71ac4159ce86bbe2eb204c190f1e9ce43ba6/surface-test.json',
5
function (data) {
6
// pre-process the data
7
var result = [];
8
for (var x = 0; x < data.x.length; x++) {
9
for (var y = 0; y < data.y.length; y++) {
10
result.push([x, data.y[y], data.z[x][y]]);
11
}
12
}
13
14
// create a surface chart
15
var chart = anychart.surface(result);
16
17
theChart = chart;
18
19
// set the x-axis label format
20
chart
21
.xAxis()
22
.labels()
23
.format(function () {
24
return data.x[Math.round(this.value)];
25
});
26
27
// set the x-axis scale maximum
28
chart.xScale().maximum(data.x.length - 1);
29
30
// set the chart paddings
31
chart.padding(50, 50, 50, 75);
32
33
// set the x/y/z-axis stroke color
34
chart.xAxis().stroke('#000');
35
chart.yAxis().stroke('#000');
36
chart.zAxis().stroke('#000');
37
38
// set the y scale minimum/maximum
39
chart.yScale().minimum(1971);
40
chart.yScale().maximum(2021);
41
42
// set the scale tick intervals
43
chart.xScale().ticks().interval(1);
44
chart.yScale().ticks().interval(5);
45
46
// set the x-axis label rotation
47
chart.xAxis().labels().rotation(90);
48
49
// hide the last label on the y-axis
50
chart.yAxis().drawLastLabel(false);
51
52
// create a color scale
53
let customColorScale = anychart.scales.linearColor();
54
customColorScale.colors([
55
'#76BA99',
56
'#FDFF00',
57
'#FD841F',
58
'#E14D2A'
59
]);
60
61
// set the color scale
62
chart.colorScale(customColorScale);
63
64
// enable and configure the color range
65
chart.colorRange().enabled(true).orientation('right');
66
67
// set the default chart rotation by the y-axis
68
chart.rotationY(40);
69
// set the default chart rotation by the z-axis
70
chart.rotationZ(130);
71
72
// set the chart title
73
chart.title('Population Growth of Top 50 Most Populous Countries Over Past 50 Years');
74
75
// set the container id for the chart
76
chart.container('container');
77
78
// initiate the visualization
79
chart.draw();
80
}
81
);
82
});
83
84
85
// rotation control y
86
let rotateY = function() {
87
let value = +document.getElementById('rotationY').value;
88
theChart.rotationY(value);
89
};
90
91
// rotation control z
92
let rotateZ = function() {
93
let value = +document.getElementById('rotationZ').value;
94
theChart.rotationZ(value);
95
};
96