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
// prevent premature chart script execution
2
anychart.onDocumentReady(function () {
3
// load data into the chart from a JSON file
4
anychart.data.loadJsonFile(
5
"https://raw.githubusercontent.com/Bepely/JsonExampleData/main/calendar2023.json",
6
// callback function to set chart data
7
(data) => chart.data(data)
8
);
9
10
// create a calendar chart
11
const chart = anychart.calendar();
12
13
// set green color to elements
14
chart.colorScale().colors(["green"]);
15
16
// disable color range
17
chart.colorRange(false);
18
19
// customize months
20
const months = chart.months();
21
// set stroke for months
22
months.stroke("black", 1);
23
// set no data stroke for months
24
months.noDataStroke("black", 1);
25
26
// customize years
27
const years = chart.years();
28
// access years' title properties
29
const yearsTitle = years.title();
30
// set font color for years' title
31
yearsTitle.fontColor("darkgray");
32
// set font size for years' title
33
yearsTitle.fontSize(23);
34
// set font weight for years' title
35
yearsTitle.fontWeight(400);
36
// set padding for years' title
37
yearsTitle.padding(0, "25%", 0, 0);
38
39
// set tooltip format function
40
chart.tooltip().format(function () {
41
// get pointed article name
42
const articleName = this.getData("name");
43
// return article name or default text
44
return articleName ? articleName : "No Article Name!";
45
});
46
47
// set the container id
48
chart.container("container");
49
50
// adjust the chart's height after drawing
51
chart.listen("chartDraw", function () {
52
document.getElementById("container").style.height =
53
chart.getActualHeight() + 5 + "px";
54
});
55
56
// set the chart title
57
chart.title("JavaScript Charting Tutorials on AnyChart Blog, 2020–2023");
58
59
// draw the chart
60
chart.draw();
61
});