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.title('Serialize chart object to JSON');
8
chart.bounds(0, 0, '50%', '100%');
9
chart.container(stage);
10
chart.draw();
11
12
// Returns chart as JSON object.
13
var json = chart.toJson();
14
15
var chartFromJson = anychart.fromJson(json);
16
chartFromJson.bounds('50%', 0, '50%', '100%');
17
chartFromJson.title('Creates chart from JSON object');
18
chartFromJson.container(stage);
19
chartFromJson.draw();
20
});
21
22
function getData() {
23
return [
24
{x: 'California', y: '2004', heat: 1704211},
25
{x: 'California', y: '2005', heat: 2782680},
26
{x: 'California', y: '2006', heat: 2992679},
27
{x: 'Illinois', y: '2004', heat: 727914},
28
{x: 'Illinois', y: '2005', heat: 1150659},
29
{x: 'Illinois', y: '2006', heat: 1134085},
30
{x: 'Massachusetts', y: '2004', heat: 238819},
31
{x: 'Massachusetts', y: '2005', heat: 157719},
32
{x: 'Massachusetts', y: '2006', heat: 887169},
33
{x: 'New York', y: '2004', heat: 1667969},
34
{x: 'New York', y: '2005', heat: 2763503},
35
{x: 'New York', y: '2006', heat: 3151022},
36
{x: 'Texas', y: '2004', heat: 219967},
37
{x: 'Texas', y: '2005', heat: 3732889},
38
{x: 'Texas', y: '2006', heat: 4185098}
39
]
40
}