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
// create data set with raw data (absolute numbers)
3
var rawData = [
4
['11 Oct', 100, 80, 40, 15, 10], // Candidates Distributed, Clicked Booking Link, etc.
5
['12 Oct', 90, 70, 35, 12, 8],
6
['13 Oct', 95, 78, 45, 16, 10],
7
['14 Oct', 84, 65, 36, 14, 8],
8
['15 Oct', 80, 60, 32, 12, 7],
9
['16 Oct', 75, 55, 30, 11, 6],
10
['17 Oct', 70, 50, 25, 9, 5],
11
['18 Oct', 65, 45, 22, 8, 4],
12
['19 Oct', 60, 40, 20, 7, 4]
13
];
14
15
// Function to calculate percentages relative to Candidates Distributed (total)
16
var percentageData = rawData.map(function (row) {
17
var total = row[1]; // Candidates Distributed is the baseline
18
19
// Ensure that we do not calculate over 100%
20
var clickedBookingLinkPercent = Math.min(Math.round((row[2] / total) * 100), 100);
21
var interviewBookedPercent = Math.min(Math.round((row[3] / total) * 100), 100);
22
var clickedReviewsLinkPercent = Math.min(Math.round((row[4] / total) * 100), 100);
23
var clickedInterviewLinkPercent = Math.min(Math.round((row[5] / total) * 100), 100);
24
25
return [
26
row[0], // Date
27
100, // Candidates Distributed is always 100% (it is the baseline)
28
clickedBookingLinkPercent,
29
interviewBookedPercent,
30
clickedReviewsLinkPercent,
31
clickedInterviewLinkPercent
32
];
33
});
34
35
// create data set for percentage data
36
var dataSet = anychart.data.set(percentageData);
37
38
// map data for each series
39
var seriesData_1 = dataSet.mapAs({'x': 0, 'value': 1}); // Candidates Distributed (always 100%)
40
var seriesData_2 = dataSet.mapAs({'x': 0, 'value': 2}); // Clicked Booking Link %
41
var seriesData_3 = dataSet.mapAs({'x': 0, 'value': 3}); // Interview Booked %
42
var seriesData_4 = dataSet.mapAs({'x': 0, 'value': 4}); // Clicked Reviews Link %
43
var seriesData_5 = dataSet.mapAs({'x': 0, 'value': 5}); // Clicked Interview Link %
44
45
// create area chart
46
var chart = anychart.area();
47
48
// turn on chart animation
49
chart.animation(true);
50
51
// turn on the crosshair
52
chart.crosshair().enabled(true).yLabel().enabled(false);
53
chart.crosshair().enabled(true).xLabel().enabled(false);
54
chart.crosshair().yStroke(null).xStroke('#fff').zIndex(99);
55
56
// set yAxis labels formatting to show percentages with no decimal points
57
chart.yAxis(0).labels().format("{%Value}%").fontSize(12);
58
59
// helper function to setup label settings for all series
60
var setupSeries = function (series, name, color) {
61
series.stroke('3 #fff 1');
62
series.fill(color || function () {
63
return this.sourceColor + ' 0.8';
64
});
65
series.name(name);
66
series.markers().zIndex(100);
67
series.clip(false);
68
series.hovered()
69
.stroke('3 #fff 1')
70
.markers().enabled(true).type('circle').size(4).stroke('1.5 #fff');
71
};
72
73
// create first series (Candidates %)
74
var series1 = chart.area(seriesData_1);
75
setupSeries(series1, 'Candidates %');
76
77
// create second series (Clicked Booking Link %)
78
var series2 = chart.area(seriesData_2);
79
setupSeries(series2, 'CBL %');
80
81
// create third series (Interview Booked %)
82
var series3 = chart.area(seriesData_3);
83
setupSeries(series3, 'IB %');
84
85
// create fourth series (Clicked Reviews Link %)
86
var series4 = chart.area(seriesData_4);
87
setupSeries(series4, 'CRL %');
88
89
// create fifth series (Clicked Interview Link %)
90
var series5 = chart.area(seriesData_5);
91
setupSeries(series5, 'CIL %');
92
93
// set interactivity and tooltip settings
94
chart.interactivity().hoverMode('by-x');
95
chart.tooltip().displayMode('union');
96
97
// turn on legend
98
chart.legend().enabled(true).fontSize(13).padding([0, 0, 25, 0]);
99
100
// set container id for the chart
101
chart.container('container');
102
103
// initiate chart drawing
104
chart.draw();
105
});
106