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 stage = anychart.graphics.create('container');
3
4
var data = getData();
5
6
var chart = anychart.heatMap(data);
7
chart.top('10%');
8
chart.title('Convert the global coordinates to local coordinates');
9
chart.container(stage);
10
chart.draw();
11
12
// Converts the global coordinates to local coordinates.
13
var localCoordinates = chart.globalToLocal(8, 8);
14
15
var rectangle = stage.rect(0, 0, 170, 30);
16
rectangle.fill({opacity: 0.1});
17
18
rectangle.setX(localCoordinates.x);
19
rectangle.setY(localCoordinates.y);
20
21
var customText = anychart.graphics.text(localCoordinates.x, localCoordinates.y, "");
22
customText.htmlText("Local coordinates [x: "
23
+ localCoordinates.x + ", y: " + localCoordinates.y + "]<br>Global coordinates [x: 8, y: 8]");
24
customText.parent(stage);
25
26
// Visualises local bounds.
27
var localBounds = stage.rect();
28
localBounds.setBounds(stage.getBounds());
29
});
30
31
function getData() {
32
return [
33
{x: 'California', y: '2004', heat: 1704211},
34
{x: 'California', y: '2005', heat: 2782680},
35
{x: 'California', y: '2006', heat: 2992679},
36
{x: 'Illinois', y: '2004', heat: 727914},
37
{x: 'Illinois', y: '2005', heat: 1150659},
38
{x: 'Illinois', y: '2006', heat: 1134085},
39
{x: 'Massachusetts', y: '2004', heat: 238819},
40
{x: 'Massachusetts', y: '2005', heat: 157719},
41
{x: 'Massachusetts', y: '2006', heat: 887169},
42
{x: 'New York', y: '2004', heat: 1667969},
43
{x: 'New York', y: '2005', heat: 2763503},
44
{x: 'New York', y: '2006', heat: 3151022},
45
{x: 'Texas', y: '2004', heat: 219967},
46
{x: 'Texas', y: '2005', heat: 3732889},
47
{x: 'Texas', y: '2006', heat: 4185098}
48
]
49
}