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 data set on our data
3
var dataSet = anychart.data.set([
4
['Jan', 225],
5
['Feb', 200],
6
['Mar', 205],
7
['Apr', 190],
8
['May', 180],
9
['Jun', 185],
10
['Jul', 195],
11
['Aug', 230],
12
['Sep', 227],
13
['Oct', 232],
14
['Nov', 228],
15
['Dec', 235]
16
]);
17
18
// map data for the first series, take x from the zero column and value from the first column of data set
19
var seriesData = dataSet.mapAs({ x: 0, value: 1 });
20
21
// create area chart
22
var chart = anychart.area();
23
24
// adding dollar symbols to yAxis labels
25
chart.yAxis().labels().format('{%Value} hrs');
26
27
// turn on chart animation
28
chart.animation(true);
29
30
// axes and scale settings
31
chart.yScale().minimum(150).maximum(300);
32
chart.yAxis().title('Sunhours');
33
chart.xAxis().labels().padding([5, 5, 0, 5]);
34
35
// chart grids
36
chart.yGrid(true).xGrid(true);
37
38
// turn on the crosshair
39
var crosshair = chart.crosshair();
40
crosshair.enabled(true).yStroke(null).xStroke('#fff').zIndex(99);
41
crosshair.yLabel(false);
42
crosshair.xLabel(false);
43
44
// set chart title text settings
45
chart
46
.title()
47
.enabled(true)
48
.useHtml(true)
49
.text(
50
'AVERAGE MONTHLY HOURS OF SUNSHINE OVER THE YEAR<br/>' +
51
'<span style="color:#212121; font-size: 13px;">the monthly total of sunhours over the year in Sydney, Australia.</span>'
52
)
53
.padding([0, 0, 20, 0]);
54
55
// create first series with mapped data
56
var series = chart.splineArea(seriesData);
57
series.name('Sunhours');
58
series.color('Gold 0.5');
59
series
60
.markers()
61
.enabled(true)
62
.type('circle')
63
.size(4)
64
.stroke('1.5 #fff')
65
.zIndex(100);
66
67
// set chart tooltip and interactivity settings
68
chart
69
.tooltip()
70
.positionMode('chart')
71
.anchor('right-top')
72
.position('right-top')
73
.offsetX(50)
74
.offsetY(50);
75
76
chart.interactivity().hoverMode('by-x');
77
78
// set container id for the chart
79
chart.container('container');
80
81
// initiate chart drawing
82
chart.draw();
83
});