HTMLcopy
x
1
<div style="display: inline-block">
2
3
</div>
4
5
<div id="container"></div>
CSScopy
15
1
<style>
2
html, body {
3
width: 100%;
4
height: 100%;
5
margin: 0;
6
padding: 0;
7
}
8
9
#container {
10
float: center;
11
width: 85%;
12
height: 800px;
13
margin: 0;
14
}
15
</style>
JavaScriptcopy
372
1
var chart1, chart2, chart3, chart4;
2
3
function createChart(container, data, bouds, levels) {
4
5
var dataTree = anychart.data.tree(data, 'as-table');
6
7
var chart = anychart.sunburst(dataTree);
8
9
var palette = anychart.palettes.distinctColors();
10
palette.items(['DodgerBlue', 'green', 'darkorange', 'gold', 'green', 'maroon']);
11
// Set palette.
12
chart.palette(palette);
13
// set point fill
14
/*chart.fill(function () { //parentColor from level 2
15
if(this.parent.parent != null) {
16
return this.parent ? anychart.color.darken(this.parentColor, 0.15) : this.mainColor
17
}
18
});*/
19
20
chart.bounds(bouds);
21
22
/*
23
chart.labels(true);
24
//chart.labels().fontFamily("");
25
chart.labels().fontSize(18);
26
chart.labels().fontWeight(100);
27
chart.radius('90%');
28
chart.innerRadius('0%');
29
*/
30
31
chart.calculationMode('parent-dependent');
32
chart.labels().format('{%Name}');
33
34
chart.level(0).enabled(levels[0]);
35
chart.level(1).enabled(levels[1]);
36
chart.level(2).enabled(levels[2]);
37
// chart.level(3).enabled(levels[3]);
38
39
chart.leaves().thickness('45%');
40
41
var l1 = anychart.standalones.label();
42
l1.text("Company Structure");
43
l1.width("100%");
44
l1.height("100%");
45
l1.fontColor("#dd2c00");
46
l1.fontSize(12);
47
l1.fontWeight(600);
48
l1.hAlign("center");
49
l1.vAlign("middle");
50
51
// set the center content
52
chart.center().content(l1);
53
54
//chart.leaves().labels().format("<span style='font-size:20px'>{%name}</span>");
55
56
chart.leaves().hovered().labels().fontColor('black');
57
chart.leaves().normal().labels().fontSize('20px');
58
59
chart.level(2).labels().format(function() {
60
return "<span style='font-size:20px'>" + this.name +
61
"</span><br/>" + " mln";
62
});
63
64
//chart.level(1).fill(this.parentColor
65
/*chart.fill(function () { //parentColor from level 2
66
if(this.parent.parent != null) {
67
return this.parent ? anychart.color.darken(this.parentColor, 0.15) : this.mainColor
68
}
69
});*/
70
var title = chart.title();
71
title.enabled(true);
72
title.text('Set word-wrap mode. This title contains averyveryveryveryveryverylongword');
73
title.wordWrap('break-normal');
74
75
// chart.level(0).label(
76
chart.labels().format(function() {
77
var value0 = this.name.split(" ");
78
var value1 = value0[0] + " ";
79
for(var i = 1; i < value0.length; i++) {
80
value1 += value0[i];
81
i == 1 ? value1 += "\n": null;
82
}
83
return value1
84
});
85
86
// chart.level(0).labels().format(function() {}
87
88
//var c1 = [255, 0, 0];
89
//var mixColor1 = anychart.color.blend(color1, color2, 0.2);
90
91
/*chart.level(1).fill(function() {
92
return this.color ? anychart.color.blend(color1, color2, 0.2) : this.mainColor
93
}*/
94
// (Green 90%green-10%grey, Blue 75-25, yellow 50-50, orange 25-75,Red 10-90)
95
96
/*chart.fill(function () { //parentColor from level 2
97
if(this.parent.parent != null) {
98
return this.parent ? anychart.color.darken(this.parentColor, 0.15) : this.mainColor
99
}
100
});*/
101
102
//chart.level(0).wordWrap();
103
//chart.level(0).wordWrap("normal");
104
//chart.level(0).wordBreak("keep-all");
105
106
107
chart.container(container).draw();
108
109
return chart;
110
}
111
112
anychart.onDocumentReady(function() {
113
var data = [
114
// {
115
// "id": "100",
116
// "name": "Root 2",
117
// "parent": null,
118
// "value": 500
119
// },
120
//
121
// {
122
// "id": "200",
123
// "name": "Root 3",
124
// "parent": null,
125
// "value": 4
126
// },
127
128
{
129
"id": "00",
130
"name": "A Resilient Reputation",
131
"parent": null,
132
"value": 1000,
133
// "fill": "DodgerBlue"
134
},
135
136
137
{
138
"parent": "00",
139
"id": "01",
140
"name": "Leadership",
141
"value": 200,
142
// "fill": "green"
143
}, {
144
"parent": "00",
145
"id": "02",
146
"name": "Performance",
147
"value": 200,
148
//"fill": "DarkOrange"
149
}, {
150
"parent": "00",
151
"id": "03",
152
"name": "Consumer",
153
"value": 200 ,
154
//"fill": "Gold"
155
}, {
156
"parent": "00",
157
"id": "04",
158
"name": "Ethics",
159
"value": 200,
160
//"fill": "green"
161
}, {
162
"parent": "00",
163
"id": "05",
164
"name": "Culture",
165
"value": 200,
166
//"fill": "maroon"
167
},
168
169
170
171
// {
172
// "parent": "50",
173
// "id": "500",
174
// "name": "Meat 2",
175
// "value": 50
176
// },
177
178
179
{
180
"parent": "01",
181
"id": "11",
182
"name": "Integrity",
183
"value": 40
184
}, {
185
"parent": "01",
186
"id": "12",
187
"name": "Diversity",
188
"value": 20,
189
// "fill": "DodgerBlue"
190
}, {
191
"parent": "01",
192
"id": "13",
193
"name": "Board Accountability",
194
"value": 45
195
}, {
196
"parent": "01",
197
"id": "14",
198
"name": "CEO Accountability",
199
"value": 45
200
}, {
201
"parent": "01",
202
"id": "15",
203
"name": "Vision",
204
"value": 25
205
}, {
206
"parent": "01",
207
"id": "16",
208
"name": "Quality Comms",
209
"value": 25
210
},
211
212
213
{
214
"parent": "02",
215
"id": "21",
216
"name": "Delivery",
217
"value": 50
218
}, {
219
"parent": "02",
220
"id": "22",
221
"name": "Meets Expectations",
222
"value": 50,
223
// "fill": "DodgerBlue"
224
}, {
225
"parent": "02",
226
"id": "23",
227
"name": "OutPerforms Market",
228
"value": 10,
229
// "fill": "green"
230
},
231
{
232
"parent": "02",
233
"id": "25",
234
"name": "Financially Sustainable",
235
"value": 50
236
}, {
237
"parent": "02",
238
"id": "26",
239
"name": "Strong Growth",
240
"value": 40
241
},
242
243
244
{
245
"parent": "03",
246
"id": "33",
247
"name": "Service",
248
"value": 40
249
}, {
250
"parent": "03",
251
"id": "34",
252
"name": "Good Products",
253
"value": 40,
254
// "fill": "DarkOrange"
255
}, {
256
"parent": "03",
257
"id": "35",
258
"name": "Competitive",
259
"value": 40,
260
// "fill": "DodgerBlue"
261
}, {
262
"parent": "03",
263
"id": "36",
264
"name": "Responsive",
265
"value": 40,
266
// "fill": "green"
267
}, {
268
"parent": "03",
269
"id": "37",
270
"name": "Innovative",
271
"value": 40
272
},
273
274
275
{
276
"parent": "04",
277
"id": "41",
278
"name": "Leadership",
279
"value": 40
280
}, {
281
"parent": "04",
282
"id": "42",
283
"name": "Values",
284
"value": 40
285
}, {
286
"parent": "04",
287
"id": "43",
288
"name": "Integrity",
289
"value": 40
290
}, {
291
"parent": "04",
292
"id": "44",
293
"name": "CEO Accountability",
294
"value": 40,
295
// "fill": "DodgerBlue"
296
}, {
297
"parent": "04",
298
"id": "45",
299
"name": "Board Accountability",
300
"value": 20,
301
// "fill": "DodgerBlue"
302
}, {
303
"parent": "04",
304
"id": "46",
305
"name": "Commitment",
306
"value": 20
307
},
308
309
310
{
311
"parent": "05",
312
"id": "51",
313
"name": "Long Term Investment",
314
"value": 40
315
}, {
316
"parent": "05",
317
"id": "52",
318
"name": "Upholds Community Standards",
319
"value": 40,
320
// "fill": "DarkOrange"
321
}, {
322
"parent": "05",
323
"id": "53",
324
"name": "Environtmentally Responsible",
325
"value": 40,
326
// "fill": "DarkOrange"
327
}, {
328
"parent": "05",
329
"id": "54",
330
"name": "Treats Customers Fairly",
331
"value": 40
332
}, {
333
"parent": "05",
334
"id": "55",
335
"name": "Management Accountability",
336
"value": 20
337
}, {
338
"parent": "05",
339
"id": "56",
340
"name": "Board Accountability",
341
"value": 20
342
}
343
];
344
345
var stage = anychart.graphics.create('container');
346
chart4 = createChart(stage, data, anychart.math.rect(0, 0, '100%', '100%'), [true,true,true,true]);
347
348
$('#' + chart4.calculationMode()).attr('checked', 'checked');
349
$('input[name=calculationMode]').on('change', function() {
350
chart4.calculationMode($(this).val());
351
});
352
353
$('#' + chart4.sort()).attr('checked', 'checked');
354
$('input[name=sort]').on('change', function() {
355
chart4.sort($(this).val());
356
});
357
var maxDepth = chart4.getStat('treeMaxDepth');
358
for (var i = 0; i <= maxDepth; i++) {
359
var enabled = chart4.level(i).enabled();
360
$('#levels').append('<input type="checkbox" name="levels" id="level ' + i + '" value="' + i + '" ' + (enabled ? 'checked' : '') + '>');
361
$('#levels').append('<label for="' + i + '">Level ' + i + '</label><br>');
362
}
363
364
365
$('input[name=levels]').on('change', function() {
366
chart4.level(+$(this).val()).enabled($(this).is(':checked'));
367
});
368
chart4.level(0).textContent().wordWrap('break-normal');
369
});
370
371
372