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
// set the data to visualize in a mosaic plot
4
let data = {
5
header: ['#', '2006', '2009', '2012', '2015', '2018', '2021'],
6
rows: [
7
['18–29', 41, 70, 81, 90, 88, 84],
8
['30–49', 6, 42, 64, 77, 78, 81],
9
['50–64', 3, 20, 39, 51, 64, 73],
10
['65+', 0, 5, 16, 35, 37, 45]
11
]
12
};
13
14
// create a mosaic plot
15
let chart = anychart.mosaic();
16
17
// set one of the pre-built mosaic plot design themes
18
anychart.theme("pastel");
19
20
// load the data to the mosaic plot
21
chart.data(data);
22
23
// configure the mosaic plot label settings
24
chart.labels()
25
.useHtml(true)
26
.format("<span style='font-size:12px; font-weight:700; color: #786b61;'>{%value}%</span>");
27
28
// set the padding between the points in the mosaic plot
29
chart.pointsPadding(3);
30
31
// set the mosaic chart title
32
chart
33
.title()
34
.enabled(true)
35
.useHtml(true)
36
.text("<span style = 'font-size:16px; font-weight:600;'>Social Media Use in U.S. by Age</span><br><span style = 'font-size:14px;'>Share of U.S. adults saying they use at least one social media platform</span>");
37
38
// format the mosaic chart tooltip using html
39
let tooltip = chart.tooltip();
40
tooltip
41
.useHtml(true)
42
.titleFormat("<b><span style='font-size:15px;'>{%SeriesName}</b>")
43
.format("<span style='font-size:13px;'><b>{%value}%</b> of people aged <b>{%x}</b> said they<br> used at least one social media platform</span>");
44
45
// set the mosaic chart container id
46
chart.container('container');
47
48
// draw the resulting mosaic chart
49
chart.draw();
50
51
});