HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function() {
2
var chart = anychart.surface(getData());
3
4
// Create color scale.
5
var customColorScale = anychart.scales.ordinalColor();
6
customColorScale.ranges([
7
{less: -1.5, color: '#C6FFDD'},
8
{from: -1.5, to: 0, color: '#FBD786'},
9
{greater: 0, color: '#f7797d'}
10
]);
11
12
// Set color scale.
13
chart.colorScale(customColorScale);
14
15
chart.title('Set color scale using value');
16
chart.container('container');
17
chart.draw();
18
19
});
20
21
function getData() {
22
return [
23
[-3, -3, -216],
24
[-3, -2, -125],
25
[-3, -1, -64],
26
[-3, 0, -27],
27
[-3, 1, -8],
28
[-3, 2, -1],
29
[-3, 3, 0],
30
[-2, -3, -125],
31
[-2, -2, -64],
32
[-2, -1, -27],
33
[-2, 0, -8],
34
[-2, 1, -1],
35
[-2, 2, 0],
36
[-2, 3, 1],
37
[-1, -3, -64],
38
[-1, -2, -27],
39
[-1, -1, -8],
40
[-1, 0, -1],
41
[-1, 1, 0],
42
[-1, 2, 1],
43
[-1, 3, 8],
44
[0, -3, -27],
45
[0, -2, -8],
46
[0, -1, -1],
47
[0, 0, 0],
48
[0, 1, 1],
49
[0, 2, 8],
50
[0, 3, 27],
51
[1, -3, -8],
52
[1, -2, -1],
53
[1, -1, 0],
54
[1, 0, 1],
55
[1, 1, 8],
56
[1, 2, 27],
57
[1, 3, 64],
58
[2, -3, -1],
59
[2, -2, 0],
60
[2, -1, 1],
61
[2, 0, 8],
62
[2, 1, 27],
63
[2, 2, 64],
64
[2, 3, 125],
65
[3, -3, 0],
66
[3, -2, 1],
67
[3, -1, 8],
68
[3, 0, 27],
69
[3, 1, 64],
70
[3, 2, 125],
71
[3, 3, 216]
72
]
73
}