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
// chart data
3
var data_1 = [
4
{x: "1", low: 1000, q1: 1050, median: 1200, q3: 1800, high: 2000},
5
{x: "2", low: 2500, q1: 3000, median: 3800, q3: 3900, high: 4000},
6
{x: "3", low: 2000, q1: 2300, median: 2500, q3: 2900, high: 3000},
7
{x: "4", low: 4000, q1: 5000, median: 5500, q3: 6500, high: 7000},
8
{x: "5", low: 8000, q1: 8400 , median: 8500, q3: 8800, high: 9000}
9
];
10
var data_2 = [
11
{x: "1", low: 1300, q1: 1400, median: 1700, q3: 2000, high: 2100, outliers:[2300,1000]},
12
{x: "2", low: 2500, q1: 3400, median: 3500, q3: 3600, high: 3700, outliers:[4000,2200], extra_inf:["Redundancy"]},
13
{x: "3", low: 2000, q1: 2300, median: 2500, q3: 2900, high: 3000, outliers:[3450,1800]},
14
{x: "4", low: 4000, q1: 5000, median: 5500, q3: 6000, high: 7000, outliers:[7100,3700]},
15
{x: "5", low: 8100, q1: 8400, median: 8500, q3: 9000, high: 9500, outliers:[9700,7600,4500]}
16
];
17
18
// create box chart
19
var chart = anychart.box();
20
21
// set chart title text settings
22
var title = chart.title();
23
title.text("ACME Corp. Salaries\nFebruary, 2015 vs January, 2015");
24
title.hAlign("center");
25
title.enabled(true);
26
27
// set axes titles settings
28
var xAxis = chart.xAxis();
29
xAxis.title(false);
30
var yAxis = chart.yAxis();
31
yAxis.title("$ per month");
32
33
// set chart yScale settings
34
chart.yScale().maximumGap(0);
35
36
// create box chart series with our data
37
chart.box(data_1);
38
var series = chart.box(data_2);
39
40
// enable the labels
41
var labels = series.labels();
42
labels.enabled(true);
43
44
// use the text format
45
labels.format(function(){
46
return(this.getData("extra_inf"));
47
});
48
49
// positioning the label
50
labels.offsetY(20);
51
52
// set container id for the chart
53
chart.container("container");
54
55
// initiate chart drawing
56
chart.draw();
57
});