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
// The data used in this sample can be obtained from the CDN
3
// https://cdn.anychart.com/samples-data/surface-chart/gdp-per-capita.json
4
anychart.data.loadJsonFile(
5
'https://cdn.anychart.com/samples-data/surface-chart/gdp-per-capita.json',
6
function (data) {
7
// pre-processing of the data
8
var result = [];
9
for (var x = 0; x < data.x.length; x++) {
10
for (var y = 0; y < data.y.length; y++) {
11
result.push([x, data.y.sort()[y], data.z[x][y]]);
12
}
13
}
14
15
// create surface chart
16
var chart = anychart.surface();
17
18
// enable markers and set data for them
19
chart.markers().enabled(true).data(result);
20
21
// set chart title
22
chart.title('GDP per capita, PPP, constant 2005 international $');
23
24
// set chart paddings
25
chart.padding(25, 50, 75, 50);
26
27
chart.rotationY(15);
28
chart.rotationZ(45);
29
30
// enable X/Y minor ticks and labels
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 X axis scale maximum
37
chart.xScale().maximum(data.x.length - 1);
38
39
// set Y scale minimum/maximum
40
chart.yScale().minimum(1995);
41
chart.yScale().maximum(2013);
42
43
// hide the last label in Y axis
44
chart.yAxis().drawLastLabel(false);
45
46
// set scales ticks intervals
47
chart.xScale().ticks().interval(50);
48
chart.yScale().ticks().interval(8);
49
chart.zScale().ticks().interval(40000);
50
51
// set X/Y/Z axis labels font size
52
chart.xAxis().labels().fontSize(10);
53
chart.xAxis().minorLabels().fontSize(10);
54
chart.yAxis().labels().fontSize(10);
55
chart.yAxis().minorLabels().fontSize(10);
56
chart.zAxis().labels().fontSize(10);
57
58
// set X axis labels rotation
59
chart.xAxis().labels().rotation(90);
60
chart.xAxis().minorLabels().rotation(90);
61
62
// set X axis labels format
63
chart
64
.xAxis()
65
.labels()
66
.format(function () {
67
return data.x[Math.round(this.value)];
68
});
69
chart
70
.xAxis()
71
.minorLabels()
72
.format(function () {
73
return data.x[Math.round(this.value)];
74
});
75
76
// set chart stroke(mesh) settings
77
chart.stroke('#666 .5');
78
79
// Create color scale
80
var customColorScale = anychart.scales.linearColor();
81
customColorScale.colors([
82
'#B5DDB6',
83
'#f9ac93',
84
'#96C8E9',
85
'#FF5555'
86
]);
87
88
// Set color scale
89
chart.colorScale(customColorScale);
90
91
// enable and configure color range
92
chart.colorRange().enabled(true).orientation('right');
93
94
// set container id for the chart
95
chart.container('container');
96
97
// initiate chart drawing
98
chart.draw();
99
}
100
);
101
});