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
anychart.onDocumentReady(function () {
2
anychart.data.loadJsonFile(
3
'https://gist.githubusercontent.com/shacheeswadia/b0d6b34a1910359e0e1a8fc0c84019a6/raw/4ab92ca6361f1bc9875d2854e2e1271bc991f86b/surfaceAreaData.json',
4
function (data) {
5
// processing of the data
6
var result = [];
7
for (var x = 0; x < data.x.length; x++) {
8
for (var y = 0; y < data.y.length; y++) {
9
result.push([x, data.y.sort()[y], data.z[x][y]]);
10
}
11
}
12
13
// create surface chart
14
var chart = anychart.surface();
15
16
// enable markers and set data for them
17
chart.markers().enabled(true).data(result);
18
19
// set x axis scale maximum
20
chart.xScale().maximum(data.x.length - 1);
21
22
// set y and z axes rotation
23
chart.rotationY(15);
24
chart.rotationZ(45);
25
26
// set y scale minimum/maximum
27
chart.yScale().minimum(2006);
28
chart.yScale().maximum(2020);
29
30
// enable x and y axes minor ticks
31
chart.xAxis().minorTicks().enabled(true);
32
chart.xAxis().minorLabels().enabled(true);
33
chart.yAxis().minorTicks().enabled(true);
34
chart.yAxis().minorLabels().enabled(true);
35
36
// set scales ticks intervals
37
chart.yScale().ticks().interval(8);
38
chart.zScale().ticks().interval(40000);
39
40
// hide the last label in y axis
41
chart.yAxis().drawLastLabel(false);
42
43
// set x, y and z axes labels font size
44
chart.xAxis().labels().fontSize(10);
45
chart.xAxis().minorLabels().fontSize(10);
46
chart.yAxis().labels().fontSize(10);
47
chart.yAxis().minorLabels().fontSize(10);
48
chart.zAxis().labels().fontSize(10);
49
50
// set x axis labels rotation
51
chart.xAxis().labels().rotation(90);
52
chart.xAxis().minorLabels().rotation(90);
53
54
// set x axis labels format
55
chart
56
.xAxis()
57
.labels()
58
.format(function () {
59
return data.x[Math.round(this.value)];
60
});
61
62
chart
63
.xAxis()
64
.minorLabels()
65
.format(function () {
66
return data.x[Math.round(this.value)];
67
});
68
69
// set x, y and z axes stroke settings
70
chart.xAxis().stroke(null);
71
chart.xAxis().ticks().stroke("1 lightgray");
72
chart.xAxis().minorTicks().stroke("1 lightgray");
73
74
chart.yAxis().stroke(null);
75
chart.yAxis().ticks().stroke("1 lightgray");
76
chart.yAxis().minorTicks().stroke("1 lightgray");
77
78
chart.zAxis().stroke(null);
79
chart.zAxis().ticks().stroke("1 lightgray");
80
chart.zAxis().minorTicks().stroke("1 lightgray");
81
82
// set chart paddings
83
chart.padding(25, 50, 75, 50);
84
85
// set chart title
86
chart.title('GDP per capita (PPP) in 2006-2020, in USD');
87
88
// set container id for the chart
89
chart.container('container');
90
91
// initiate chart drawing
92
chart.draw();
93
}
94
);
95
});