HTMLcopy
1
<div id="container"></div>
CSScopy
5
1
html, body, #container {
2
width: 100%;
3
margin: 0;
4
padding: 0;
5
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function() {
2
// load the json file
3
anychart.data.loadJsonFile(
4
'https://gist.githubusercontent.com/shacheeswadia/56f3867eb6f8fcc4532e7ac458c8d9f7/raw/702f30b457cc1b573093c6977a69958fb741ede6/calendarData.json',
5
// create a function with the data parameter
6
function(data) {
7
// define a dataset variable to store the data
8
var dataset = anychart.data.set(data);
9
10
// map the data
11
var mapping = dataset.mapAs({
12
x: 'date',
13
value: 'level'
14
});
15
16
// pass the mapped data to the calendar function
17
var chart = anychart.calendar(mapping);
18
19
// specify the color of the background
20
chart.background('#0d1117');
21
22
// configure a custom color scale
23
var customColorScale = anychart.scales.ordinalColor();
24
customColorScale.ranges([
25
{equal: 1, color: '#400554'},
26
{equal: 2, color: '#693699'},
27
{equal: 3, color: '#7c40a9'},
28
{equal: 4, color: '#9570dd'}
29
]);
30
31
// set the custom color scale
32
chart.colorScale(customColorScale);
33
34
// hide the color legend
35
chart.colorRange(false);
36
37
// remove the stroke
38
chart.months()
39
.stroke(false)
40
.noDataStroke(false);
41
42
// set the spacing and other options
43
chart.days()
44
.spacing(4)
45
.stroke(false)
46
.noDataStroke(false)
47
.noDataFill('#161b22')
48
.noDataHatchFill(false);
49
50
// set the height of the chart
51
chart.listen('chartDraw', function() {
52
document.getElementById('container').style.height = chart.getActualHeight() + 'px';
53
});
54
55
// set and customize the chart title
56
var title = chart.title();
57
title.enabled(true);
58
title
59
.text('GitHub Contributions of Mike Bostock in 2017–2021')
60
.fontSize(22)
61
.fontWeight(500)
62
.fontColor('#dfdfdf')
63
.padding(10);
64
65
// configure the chart tooltip
66
chart.tooltip()
67
.format('{%contributionCount} contributions');
68
69
// configure the inverted order of years
70
chart.years().inverted(true);
71
72
// set the container reference
73
chart.container('container');
74
75
// draw the resulting chart
76
chart.draw();
77
78
});
79
});