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
3
// create a stage
4
var stage = anychart.graphics.create("container");
5
6
// Apply the theme (if applicable)
7
anychart.theme(anychart.themes.marketForecast);
8
9
stage
10
.credits()
11
.enabled(true)
12
.url('https://www.marketforecast.com')
13
.logoSrc('https://www.marketforecast.com/favicon.ico')
14
.text('Copyright MarketForecast {CY}');
15
16
17
// Data for the charts
18
var dataSet = anychart.data.set([
19
['Weapon System', 315, 396, 2255],
20
['Surveillance Radar', 1330, 1695, 10305],
21
['Command and control (C2) system', 330, 616, 3467],
22
['Fire Control System', 165, 225, 1310]
23
]);
24
25
var SeriesFY = dataSet.mapAs({ x: 0, value: 1 });
26
var SeriesLY = dataSet.mapAs({ x: 0, value: 2 });
27
28
// Create and configure the standalone title
29
var stagetitle = anychart.standalones.title();
30
stagetitle
31
.enabled(true)
32
.useHtml(true)
33
.padding([10, 0, 10, 0]) // Add padding to create space around the title
34
.text(
35
'<span style="font-size: 16px; font-weight: bold;">{{SEGMENTITEM1}} - {{TOPIC}} Market Forecast to {LY} by {SEGMENT2}</span>'
36
);
37
38
// Set the container for the title and draw it
39
stagetitle.container(stage);
40
stagetitle.draw();
41
42
// create and configure the first pie chart (smaller)
43
var chartFY = anychart.pie(SeriesFY);
44
45
// Set chart margin settings
46
chartFY.padding(5, 5, 5, 5);
47
48
// set the chart title
49
var title = chartFY.title();
50
// enable title
51
title.enabled(true);
52
title.text("{FY market size} US$ XXX million / billion");
53
title.orientation("bottom");
54
title.align("center");
55
title.fontSize(12);
56
57
58
// Configure labels
59
chartFY.labels().position('outside');
60
61
// set chart legend settings
62
chartFY.legend().enabled(false);
63
64
// Adjust the bounds to make chartFY smaller
65
chartFY.bounds(0, "20%", "40%", "60%");
66
chartFY.background().stroke(null);
67
chartFY.innerRadius("30%");
68
69
// create and configure a label
70
var labelFY = anychart.standalones.label();
71
labelFY.text("{FY}");
72
labelFY.width("100%");
73
labelFY.height("100%");
74
labelFY.fontColor("#003A70");
75
labelFY.fontWeight("bold");
76
labelFY.hAlign("center");
77
labelFY.vAlign("middle");
78
// set the label as the center content
79
chartFY.center().content(labelFY);
80
81
// Configure tooltips
82
chartFY.tooltip().title().fontColor("#FFFFFF"); // Set tooltip text color
83
chartFY.tooltip().title().fontSize(14); // Set tooltip font size
84
chartFY.tooltip().fontColor("#FFFFFF"); // Set tooltip text color
85
chartFY.tooltip().fontSize(12); // Set tooltip font size
86
chartFY.tooltip().padding(10); // Set tooltip padding
87
chartFY.tooltip().format("{%Value}"); // Include the name, value, and percentage in the tooltip
88
89
// Customize the tooltip title and content
90
chartFY.tooltip()
91
.titleFormat(function () {
92
return '' + this.getData('x');
93
})
94
.format(function () {
95
return '{FY} : ' + anychart.format.number(this.getData('value'), {
96
groupsSeparator: ',',
97
decimalSeparator: '.'
98
}) + ' US$ Million';
99
});
100
101
// Set a white border around each slice
102
chartFY.stroke("1 #FFFFFF");
103
104
// set the chart container
105
chartFY.container(stage);
106
// initiate drawing the chart
107
chartFY.draw();
108
109
// create and configure the second pie chart (larger)
110
var chartLY = anychart.pie(SeriesLY);
111
112
// Set chart margin settings
113
chartLY.padding(5, 5, 5, 5);
114
115
// set the chart title
116
var title = chartLY.title();
117
title.enabled(true);
118
title.text("{LY market size} US$ XXX million / billion");
119
title.orientation("bottom");
120
title.align("center");
121
title.fontSize(12);
122
123
124
// Configure labels
125
chartLY.labels().position('outside');
126
127
// set chart legend settings
128
chartLY.legend().enabled(false);
129
130
// Adjust the bounds to make chartLY larger
131
chartLY.bounds("40%", "10%", "60%", "80%");
132
chartLY.background().stroke(null);
133
chartLY.innerRadius("30%");
134
135
// create and configure a label
136
var labelLY = anychart.standalones.label();
137
labelLY.text("{LY}");
138
labelLY.width("100%");
139
labelLY.height("100%");
140
labelLY.fontColor("#003A70");
141
labelLY.fontWeight("bold");
142
labelLY.hAlign("center");
143
labelLY.vAlign("middle");
144
// set the label as the center content
145
chartLY.center().content(labelLY);
146
147
// Configure tooltips
148
chartLY.tooltip().title().fontColor("#FFFFFF"); // Set tooltip text color
149
chartLY.tooltip().title().fontSize(14); // Set tooltip font size
150
chartLY.tooltip().fontColor("#FFFFFF"); // Set tooltip text color
151
chartLY.tooltip().fontSize(12); // Set tooltip font size
152
chartLY.tooltip().padding(10); // Set tooltip padding
153
chartLY.tooltip().format("{%Value}"); // Include the name, value, and percentage in the tooltip
154
155
// Customize the tooltip title and content
156
chartLY.tooltip()
157
.titleFormat(function () {
158
return '' + this.getData('x');
159
})
160
.format(function () {
161
return '{LY} : ' + anychart.format.number(this.getData('value'), {
162
groupsSeparator: ',',
163
decimalSeparator: '.'
164
}) + ' US$ Million';
165
});
166
167
// Set a white border around each slice
168
chartLY.stroke("1 #FFFFFF");
169
170
// set the chart container
171
chartLY.container(stage);
172
// initiate drawing the chart
173
chartLY.draw();
174
175
176
// TODO: Create Standalone interactive legend using both charts.
177
// https://playground.anychart.com/docs/v8/samples/CS_Legend_Standalone_02
178
// For export to svg - using the legend from one chart is sufficient
179
180
// For now create a standalone legend
181
var legend = anychart.standalones.legend();
182
183
// set the source of legend items
184
legend.itemsSource([chartFY]);
185
186
// set the padding of the legend
187
legend.padding({ top: 10, bottom: 20 });
188
legend.position("bottom");
189
190
// set the container for the legend
191
legend.container(stage);
192
193
// draw the legend
194
legend.draw();
195
});
196