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
3
// create a column chart
4
var chart = anychart.column();
5
6
// create a data set
7
var dataSet = anychart.data.set([
8
["Virat Kohli", "India", "148", "100", "48"],
9
["Max O'Dowd", "Netherlands", "106", "88", "48"],
10
["Suryakumar Yadav", "India", "81", "104", "54"],
11
["JD Butler", "England", "87", "96", "42"],
12
["Kusal Mendis", "Sri Lanka", "95", "68", "60"],
13
["Sikandar Raza", "Zimbabwe", "89", "64", "66"],
14
["Pathum Nissanka", "Sri Lanka", "114", "52", "48"],
15
["AD Hales", "England", "76", "76", "60"],
16
["Lorkan Tucker", "Ireland", "104", "76", "24"],
17
["Glenn Phillips", "New Zealand", "77", "76", "48"]
18
]);
19
20
// map the data
21
var firstSeriesData = dataSet.mapAs({x: 0, value: 4});
22
var secondSeriesData = dataSet.mapAs({x: 0, value: 3});
23
var thirdSeriesData = dataSet.mapAs({x: 0, value: 2});
24
25
// add axis titles
26
chart.xAxis().title("Batsman");
27
chart.yAxis().title("Number of runs");
28
29
// stack values on the y scale
30
chart.yScale().stackMode("percent");
31
32
// a function to configure label, and color settings for all series
33
var setupSeries = function (series, name, color) {
34
series.name(name).stroke("2 #fff 1").fill(color);
35
};
36
37
// store the series
38
var series;
39
40
// create the first series with the function
41
firstSeries = chart.column(firstSeriesData);
42
setupSeries(firstSeries, "Runs scored with Sixes", "#eb2362");
43
44
// create the second series with the function
45
secondSeries = chart.column(secondSeriesData);
46
setupSeries(secondSeries, "Runs scored with Fours", "#00b1e5");
47
48
// create the third series with the function
49
thirdSeries = chart.column(thirdSeriesData);
50
setupSeries(thirdSeries, "Running between the wickets", "#0f0449");
51
52
// turn on and configure the legend
53
chart.legend().enabled(true).fontSize(14).padding([10, 0, 10, 0]);
54
55
// customize the tooltip
56
chart.tooltip().titleFormat(function () {
57
return this.x + " — " + this.points[0].getStat("categoryYSum");
58
});
59
60
// set the union tooltip display mode
61
chart.tooltip().displayMode("union");
62
63
// rotate the x labels to make all of them visible
64
chart.xAxis().labels().rotation(-90);
65
66
// add a chart title
67
chart.title("Top 10 Run Scorers at ICC Men's T20 World Cup 2022");
68
69
// customize the chart title
70
chart.title().fontSize(18).fontColor("#2b2b2b").padding([5, 0, 0, 0]);
71
72
// set the container element
73
chart.container("container");
74
75
// display the chart
76
chart.draw();
77
78
});