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
// create stage
3
var stage = anychart.graphics.create('container');
4
5
// create column chart first
6
var chartFirst = anychart.column();
7
// set chart bounds
8
chartFirst.bounds(0, 0, '100%', '75%');
9
// set chart title text settings
10
chartFirst
11
.title()
12
.enabled(true)
13
.useHtml(true)
14
.text(
15
'Average max and min Temperatures in (°F)\n' +
16
'and Precipitation Totals in mm.'
17
);
18
// enable the grid
19
chartFirst.yGrid(true).yMinorGrid(true);
20
21
// create range-data with passed data
22
var temperatureData = anychart.data.set(getTemperatureData());
23
// sets mapping for range-bar series
24
var temperatures = temperatureData.mapAs({ x: 'month' });
25
26
// create series
27
var seriesTemperature = chartFirst.rangeColumn(temperatures);
28
// set name
29
seriesTemperature
30
.name('Temperatures')
31
// set color series
32
.color('#DB5854');
33
// format labels
34
seriesTemperature
35
.labels()
36
.enabled(true)
37
.fontColor('#DB5854')
38
.fontWeight('bold')
39
.format('{%low} - {%high}');
40
// format tooltip
41
seriesTemperature.tooltip().titleFormat('Temperature in {%X}');
42
43
// create column chart second
44
var chartSecond = anychart.column();
45
chartSecond.bounds(0, '75%', '100%', '25%');
46
// create column-data with passed data
47
var precipitationData = anychart.data.set(getPrecipitationData());
48
// sets mapping for column-bar series
49
var precipitations = precipitationData.mapAs({ x: 0, value: 1 });
50
51
// create series
52
var seriesPrecipitation = chartSecond.column(precipitations);
53
// set name
54
seriesPrecipitation.name('Precipitation');
55
// format labels
56
seriesPrecipitation.labels().enabled(true).format('{%Value}mm');
57
// format tooltip
58
seriesPrecipitation.tooltip().format('Precipitation: {%Value}mm');
59
60
// set the max and min values on the axes
61
chartSecond.yScale().minimum(0).maximum(6);
62
63
// set container stage for the chart and initiate chart drawing
64
chartFirst.container(stage).draw();
65
// set container stage for the chart and initiate chart drawing
66
chartSecond.container(stage).draw();
67
});
68
69
function getTemperatureData() {
70
return [
71
{ low: 22, high: 36, month: 'Jan' },
72
{ low: 24, high: 40, month: 'Feb' },
73
{ low: 30, high: 48, month: 'Mar' },
74
{ low: 40, high: 59, month: 'Apr' },
75
{ low: 50, high: 69, month: 'May' },
76
{ low: 59, high: 78, month: 'June' },
77
{ low: 65, high: 82, month: 'July' },
78
{ low: 64, high: 81, month: 'Aug' },
79
{ low: 56, high: 73, month: 'Sep' },
80
{ low: 45, high: 62, month: 'Oct' }
81
];
82
}
83
84
function getPrecipitationData() {
85
return [
86
['Jan', 3.6],
87
['Feb', 2.8],
88
['Mar', 4.2],
89
['Apr', 4.5],
90
['May', 4.2],
91
['June', 4.3],
92
['July', 3.7],
93
['Aug', 4],
94
['Sep', 4.6],
95
['Oct', 4.4]
96
];
97
}